簡體   English   中英

Internet Explorer中的onchange

[英]onchange in Internet Explorer

為什么我不能使用onChange ie? 有解決方案嗎?

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>

功能:

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();
        }

嘗試將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');
});

您可以使用jQuery來修復此問題代碼將是這樣的:

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

三個可能有幫助的觀察:

  1. 不再需要支持IE6及以下版本。 new XMLHttpRequest()就足夠了。
  2. 你應該調用.open() 之后設置onreadystatechange 在某些瀏覽器(probaby IE)中,調用.open()計為“新請求”並清除readystatechange處理程序。
  3. 較舊版本的IE(IE7?)不喜歡<select>上的this.value 相反,你應該使用this.options[this.selectedIndex].value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM