我一直试图通过onChange事件传递JS变量,但继续接收
谷歌浏览器下的未捕获的TypeError:无法读取null的“firstChild”属性
。以下是我的代码:
artistID = album_select.substring(0, album_select.indexOf('/'));
albumID = album_select.substring(album_select.indexOf('/')+1, album_select.length);
var count = 0;
var tracklist = '';
for(track in albumlist[albumID][2]){
count++;
tracklist+="<option id='"+album+"'>"+track+"</option>";
}
hstr+="<form><select size='"+count+"' onChange='parent.loadSong(this.value, document.getElementById(\"album_select\").firstChild.nodeValue, document.getElementById(\"artistID\").firstChild.nodeValue)' style='font-size:2em;'>";
hstr+=tracklist;
hstr+="</form></select>";
答案 0 :(得分:1)
字符串的这一部分:
document.getElementById(\"artistID\")
正在寻找"artistID"
的ID。
我假设您打算连接变量。
"...document.getElementById('" + artistID + "')..."
听起来这个人也需要它:
"...document.getElementById('" + album_select + "')..."