onchange事件怎么触发不了呀?

https://img4.mukewang.com/5c6a6be40001000405210858.jpg

LEATH
浏览 2144回答 2
2回答

长风秋雁

index = document.getElementById("selID").selectedIndex;citys = arr[index];把这两句放到onchange事件里面开头去,重新赋值。不然index的值一直都是0

MMMHUHU

&nbsp; &nbsp; selID.onchange = function() {&nbsp; &nbsp; &nbsp; &nbsp; subNode.options.length = 0;&nbsp; &nbsp; &nbsp; &nbsp; index = this.selectedIndex;&nbsp; &nbsp; &nbsp; &nbsp; citys = arr[index];&nbsp; &nbsp; &nbsp; &nbsp; for (var x = 0; x < citys.length; x++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var optNode = document.createElement("option");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; optNode.innerText = citys[x];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subNode.appendChild(optNode);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript