選択またはテキストのオンチェンジイベントは、(キーボード入力を介して)選択またはJSでテキストに値を割り当てる必要があります。
たとえば、ページがロードされた後、document.getElementByIDを使用する必要がありますJSでのオンチェンジイベントを手動でトリガーするには、JSが選択またはテキストに直接割り当てることはできません。
document.getElementByid( "staving")。fireevent( 'onchange')実装、
コードコピーは次のとおりです。
<head>
<Meta http-equiv = "content-type" content = "text /html; charset = gb2312" />
<title> un unt ittitled document </title>
<script type = "text/javascript">
var provinces = new Array();
州["hubei"] = ["wuhan"、 "xiangyang"、 "suizhou"、 "yichang"、 "shiyan"];
州["sichuan"] = ["chengdu"、 "neijiang"、 "dazhou"];
州["henan"] = ["zhengzhou"、 "nanyang"、 "xinyang"、 "luohe"];
関数changeprovince()
{
var prov = document.getElementById( "province")。value;
var city = document.getElementById( "City");
city.options.length = 0;
for(var i in provinces [prov])
{
city.options.add(new option(provinces [prov] [i]、provinces [prov] [i]));
}
}
window.onload = function(){
var province = document.getElementById( "stavince");
for(州のvarインデックス)
{
// alert(index);
province.options.add(new option(index、index));
}
Province.fireevent( "onchange");
};
</script>
</head>
<body>
州:<select id = "province" onchange = "changeprovince()"> </select>
都市:<select id = "city"> </select>
</body>
</html>