我正在研究一个脚本,该脚本从下拉选择列表中的选定选项抓取值并将其分配给对象。我遇到的唯一问题是它说我有一个空对象。使用普通javascript抓取选择值DOM
的.js文件如下:
var s = document.getElementById('mode');
alert(s.options[s.options.selectedIndex].value);
function selectValue(){
yo.newSelect(s.options[s.options.selectedIndex].value);
return true;
}
的HTML如下:
<div id="text_editing">
<form action="javascript:;" method="post" onsubmit="editHomePage()">
<select name="CYD" id="mode" onchange="selectValue()">
<option value="Home">Home</option>
<option value="About">About</option>
<option value="Contact">Contact</option>
</select>
<textarea name="sexyText" row="500" col=500">
</textarea>
<input value="submit" name="text_submit" type="submit" onclick="selectValue()">
</form>
我只是想找纯JS的解决方案。我对使用jQuery这样的小站点不感兴趣。
1)在是什么浏览器,你测试此? - 2)NULL对象是Alert框的结果? – 2012-03-23 00:19:24
Chrome。警报框根本不会弹出。我从firebug lite获得这个信息。 – VinceOmega 2012-03-23 00:32:48