0

我有一个 HTML JS 代码:

<form action="/resize" method="GET" name="resolutionForm">
 <select name="res" id="res" onchange="checkzoom(this.value); checkcut('centercropcheck')">
  <option value="original"> Original</option><option value="800x600">800x600</option>
 </select>
 <input type="checkbox" id="stretchcheck" name="stretch" onclick="verificastretch(this.id);">Esticar
 <div id="results">
  <span>original: </span>
  <span>200x200</span>
  <span>zoom: </span>
  <span>0x</span>
  <span id="zoom">0x</span></span>
 </div>
</form>
<script type="text/javascript">
 function elembyid(id){
    return document.getElementById(id);
 }
 function checkzoom(v){
    if(v == '200x200' || v == 'original'){
        var zoom = '0x';
    }else{
        if(elembyid('stretchcheck').checked){
            verificastretch('stretchcheck');
        }else{
            var novow = Number(v.substr(0,v.lastIndexOf("x")));
            var novoh = Number(v.substr(v.lastIndexOf("x") +1, v.length));
            //alert('novow'+novow+'novoh'+novoh);
            var tamzoomw = novow / 200;
            var tamzoomh = novoh / 200;
            if(tamzoomw < tamzoomh){
                var zoom = (tamzoomw.length > 3? tamzoomw.toFixed(2) : tamzoomw)+'x';
            }else{
                var zoom = (tamzoomh.length > 3? tamzoomh.toFixed(2) : tamzoomh)+'x';
            }
        }
        elembyid('zoom').innerHTML = zoom;
    }
 }
 function verificastretch(id){
    var v = elembyid('res').value;
    if(v == '200x200' || v == 'original'){
        checkzoom(v);
    }else{
        if(elembyid(id).checked){
            //alert('aqui');
            var novow = Number(v.substr(0,v.lastIndexOf("x")));
            var novoh = Number(v.substr(v.lastIndexOf("x") +1, v.length));
            //alert('novow'+novow+'novoh'+novoh);
            var tamzoomw = novow / 200;
            var tamzoomh = novoh / 200;
            var zoom = (tamzoomw.length > 3? tamzoomw.toFixed(2) : tamzoomw)+'x '+(tamzoomh.length > 3? tamzoomh.toFixed(2) : tamzoomh)+'x';
            alert(zoom);
            elembyid('zoom').innerHTML = zoom;
        }else{
            checkzoom(v);
        }
    }
 }
</script>

当拉伸的复选框被选中,并且我更改了 select res 的选定选项时,我在 div id = "result" 中得到未定义,我该如何解决这个问题?在文件中,代码没有这样的';' 因为复制时出错。

4

1 回答 1

0

在 if 条件之后

        if(elembyid('stretchcheck').checked){
            verificastretch('stretchcheck');
        }else{
            …
        }

已完成并verificastretch已将 span 正确设置zoom4x 3x, spanzoomundefined变量覆盖zoom

        elembyid('zoom').innerHTML = zoom;

我认为您希望在 else 子句中使用该行。

您可以通过使用调试器并从函数checkzoom开始单步执行代码来发现这一点。

于 2013-02-19T21:59:53.637 回答