OnChange不触发-不是函数错误

时间:2019-07-16 14:19:57

标签: javascript onchange

我有一个选择框,当用户进行选择但不触发脚本时,我想触发js。

<!doctype html>
<html lang="en-gb">
<head>
<script>
    function registration(obj){
    if(obj == "" || obj == "TSW"){
        document.getElementById("registration-item").innerHTML = "";
        return;
    } else {
        if(window.XMLHttpRequest){
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function(){
            if(this.readyState == 4 && this.status == 200){
                document.getElementById("registration-item").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","/../scripts/getitems.php?q="+obj,true);
        xmlhttp.send();
        var show = document.getElementById("items");
        show.className = show.className.replace(/\bhidden\b/g,"");
    }
}
</script>
</head>

这是与脚本交互的选择字段:

<select class="select form-control" type="text" onchange="registration(this.value);" name="registration" id="registration">
    <option value="TSW">TSW/CST</option>
    <option value="ILM">ILM</option>
    <option value="IOSH">IOSH</option>
</select>
<div class="form_field hidden" id="items">
    <label>Available Registrations</label>
    <select class="select js-example-basic-single form-control" id="registration-item" name="registration-item"></select>
</div>

我了解它很可能找不到该功能,但看不到我做错了什么?有人可以指出吗?

0 个答案:

没有答案