0

我试图在文本字段更改时触发AJAX GET请求,但我无法OnChange Listener正常工作,如果有人能解释为什么它不工作,我将不胜感激。

document.getElementById('address1').attachEvent("OnChange", loadXMLDoc);
function loadXMLDoc()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","http://myurl.co.uk/AddressFinder/UpdateControler.php",true);
    xmlhttp.send();
}
4

1 回答 1

1
if(window.addEventListener) {
    document.getElementById('address1').addEventListener("change", loadXMLDoc);
} else if (window.attachEvent){
    document.getElementById('address1').attachEvent("onchange", loadXMLDoc);
}

function loadXMLDoc(){
   alert('worked');   
}
于 2012-08-28T23:04:47.127 回答