此earler代碼工作fine.but不知道突然停止工作..更改位置代碼後。JavaScript的一些如何停止工作
give error :
- Uncaught TypeError: Cannot read property 'options' of undefined (in chrome)
- no element found (in firefox)
var inputs = document.getElementsByTagName("select"); //get array of select tag
var sSrnti = inputs[0].options[inputs[0].selectedIndex].value; //get selected value of first list
var sType = inputs[1].options[inputs[1].selectedIndex].value;//get selected value of second list
var sStatus = inputs[2].options[inputs[2].selectedIndex].value;//get selected value of third list
請幫助我..謝謝
你從哪裏移動代碼並將它放在哪裏? – jeff
至少有一個'input [0]','inputs [1]',inputs [2]'出現'null'。我猜測,在執行代碼的時間或上下文中,元素不存在於DOM中。 –
我想到的第一件事就是您已將腳本移動到實際的html之上。這會導致它在你的dom樹被加載之前運行,因此爲''document.getElementsByTagName(「select」);''返回'undefined',導致下一行出現錯誤。 – Kippie