简体   繁体   English

Internet Explorer中的onchange

[英]onchange in Internet Explorer

Why cant I use onChange in ie? 为什么我不能使用onChange ie? And is there a solution for this? 有解决方案吗?

HTML: HTML:

<select id="auto_doors" style="display:none;" name="auto_doors" onchange="updateField(this.value, 'auto_fuel', 5, 6, this.parentNode.id), resetBelow(4,'auto'), show('auto_fuel')">
</select>

Function: 功能:

if (jQuery.browser.msie) { setTimeout(DoSomething, 0); } else { DoSomething(); }
        function updateField(str, id, prevvalue, value, vehicletype)
        {
        if (str=="")
          {
          document.getElementById(id).innerHTML="";
          return;
          } 
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById(id).innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open("GET","inc/form_rest.php?q="+str+"&prevvalue="+prevvalue+"&value="+value+"&vehicletype="+vehicletype,true);
        xmlhttp.send();
        }

Try binding the on on change event to the auto_doors element like this instead: 尝试将on on change事件绑定到auto_doors元素,而不是:

$("#auto_doors").change(function(){
   updateField(this.value, 'auto_fuel', 5, 6, this.parentNode.id), resetBelow(4,'auto'), show('auto_fuel');
});

You can use jQuery to fix this problem code will be something like this: 您可以使用jQuery来修复此问题代码将是这样的:

$('#auto_doors').change(function() {
  alert('Handler for .change() called.');
});

Three observations that may help: 三个可能有帮助的观察:

  1. There is no need to support IE6 and below anymore. 不再需要支持IE6及以下版本。 new XMLHttpRequest() is sufficient. new XMLHttpRequest()就足够了。
  2. You should set onreadystatechange after calling .open() . 你应该调用.open() 之后设置onreadystatechange In some browsers (probaby just IE) calling .open() counts as a "new request" and clears the readystatechange handler. 在某些浏览器(probaby IE)中,调用.open()计为“新请求”并清除readystatechange处理程序。
  3. Older versions of IE (IE7?) don't like this.value on a <select> . 较旧版本的IE(IE7?)不喜欢<select>上的this.value Instead, you should use this.options[this.selectedIndex].value . 相反,你应该使用this.options[this.selectedIndex].value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM