earler이 코드는 잘 작동하지만 갑자기 작동을 멈추는 지 모르겠다. 코드 위치를 변경 한 후.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
'inputs [0]','inputs [1]','inputs [2]'중 적어도 하나는'null '을 나타냅니다. 그 요소가 코드가 실행되는 시간이나 컨텍스트에서 DOM에 존재하지 않는다고 추측합니다. –
내 마음에 제일 먼저 오는 것은 스크립트를 실제 HTML 위에 올려 놓은 것입니다. 이렇게하면 dom 트리가로드되기 전에 실행되어''document.getElementsByTagName ("select");''에 대해''undefined ''를 반환하여 다음 줄에서 오류가 발생합니다. – Kippie