function call(op) {
var x = op.selectedOptions[0].textContent;
var n = x.substring(0, 3);
//alert(n);
document.pts.inputbox.value = n;
document.pts.submit();
}
Run Code Online (Sandbox Code Playgroud)
我有一个函数,它从列表框中的选定选项中获取标签值,然后它会分析前3个字母并将该信息传递给输入框值.
问题在于js如何抓取选定的选项标签文本内容.它似乎在Chrome中工作得很好,但在firefox17和IE9中没有任何反应.有关更好地获取所选选项标签值的任何建议吗?
编辑:我不能使用选项值,该值保留为更具体的东西在JSfiddle中一切正常.
The*_*pha 27
试试这个
function call(op) {
var x = op.options[op.selectedIndex].text;
var n = x.substring(0, 3);
alert('Index : '+op.selectedIndex+' and first 3 lettrs are : '+n);
}
Run Code Online (Sandbox Code Playgroud)
演示.