0

ieでonChangeを使用できないのはなぜですか?そして、これに対する解決策はありますか?

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

3 に答える 3

1

代わりに、次のように 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');
});
于 2013-02-03T20:35:03.370 に答える
1

jQuery を使用してこの問題を修正できます。コードは次のようになります。

$('#auto_doors').change(function() {
  alert('Handler for .change() called.');
});
于 2013-02-03T20:37:14.740 に答える
0

役立つ可能性のある 3 つの観察事項:

  1. IE6 以下をサポートする必要はなくなりました。new XMLHttpRequest()十分なものです。
  2. を呼び出してから設定onreadystatechange .open()てください。一部のブラウザー (おそらく IE のみ) では、呼び出し.open()は「新しい要求」としてカウントされ、readystatechange ハンドラーがクリアされます。
  3. 古いバージョンの IE (IE7?) はthis.value<select>. 代わりに、 を使用する必要がありますthis.options[this.selectedIndex].value
于 2013-02-03T20:31:58.157 に答える