Javascript Internet Explorer不在选择框中加载值
不知何故,IE不会加载我用Ajax更新的选择框中的值,但其他浏览器会加载 HTML: Ajax功能:Javascript Internet Explorer不在选择框中加载值,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,不知何故,IE不会加载我用Ajax更新的选择框中的值,但其他浏览器会加载 HTML: Ajax功能: function updateField(str, id, prevvalue, value, vehicletype) { if (str=="") { document.getElementById(id).innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chr
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();
}
在.change()调用中,尝试使用$(this).val()而不是this.value。在ie中,事件在窗口对象而不是实际元素本身上被调用,这会影响“this”的范围$(这)应该为您规范化它,因为它现在是jQuery对象,所以您必须使用jQuery函数而不是原生js属性,因此需要使用.val()
另外,我强烈建议使用$.ajax()而不是自己处理跨浏览器调用。使用jQuery的一半目的是为了克服跨浏览器的噩梦。如果要将其加载到页面上,请继续编写所有脚本jQuery 如果您坚持使用jQuery,至少是DOM遍历和Ajax,这是它最擅长的,那么您可能会找到答案!我没有使用jQuery和Ajax的经验,我真的需要帮助,因为我还需要做很多工作。可能的重复
$("#auto_year").change(function(){
updateField(this.value, 'auto_brand', 1, 2, this.parentNode.id), resetBelow(0,'auto'), show('auto_brand');
});
$("#auto_brand").change(function(){
updateField(this.value, 'auto_model', 2, 3, this.parentNode.id), resetBelow(1,'auto'), show('auto_model');
});
$("#auto_model").change(function(){
updateField(this.value, 'auto_bodywork', 3, 4, this.parentNode.id), resetBelow(2,'auto'), show('auto_bodywork');
});
$("#auto_bodywork").change(function(){
updateField(this.value, 'auto_doors', 4, 5, this.parentNode.id), resetBelow(3,'auto'), show('auto_doors');
});
$("#auto_doors").change(function(){
updateField(this.value, 'auto_fuel', 5, 6, this.parentNode.id), resetBelow(4,'auto'), show('auto_fuel');
});
$("#auto_fuel").change(function(){
updateField(this.value, 'auto_gearbox', 6, 7, this.parentNode.id), resetBelow(5,'auto'), show('auto_gearbox');
});
$("#auto_gearbox").change(function(){
updateField(this.value, 'auto_type', 7, 8, this.parentNode.id), resetBelow(6,'auto'), show('auto_type');
});
$("#auto_type").change(function(){
updateField(this.value, 'auto_uitvoering', 8, 9, this.parentNode.id), resetBelow(7,'auto'), show('auto_uitvoering');
});
$("#auto_uitvoering").change(function(){
updateField(this.value, '', 9, 10, this.parentNode.id), resetBelow(8,'auto');
});
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();
}