【发布时间】:2014-10-05 19:59:09
【问题描述】:
我正在尝试制作一个为 IE8 开发的简单 Java 脚本页面,该页面与 IE9 及更高版本兼容。当我尝试使用原型的 getValue() 方法时,选择标签给出“TypeError:对象不支持属性或方法'getValue'”。此页面在所有版本的 IE 中都能正常工作在 IE9 中,少数没有管理员权限的县用户除外。
有人可以帮我解决这个问题吗?
<!DOCTYPE html>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="prototype.js"></SCRIPT>
</head>
<body style="width:500px">
<form id="example" action="#" onsubmit="return false">
<div id="container">
<select size="7" style="width:auto;" name="commonRTSelect" id="commonRTSelect" multiple>
<option value="volvo" selected>Volvo</option>
<option value="saab" selected>Saab</option>
<option value="mercedes" selected>Mercedes</option>
<option value="audi">Audi</option>
</select>
<input type="text" style="width:auto;" name="fname" id="fname" value="madhu">
<br>
</div>
</form>
<input type="button" value="Toggle" onclick="showResult();"/>
<script>
function showResult() {
var elems = $('container').select('input','select','textarea');
elems.each( function(e){
if(e instanceof HTMLElement) {
alert("Yes.."+e.name+" is an instance of HTMLElement");
}
else {
alert("No "+e.name+" is not an instance of HTMLElement. it is " + e);
}
});
try{
alert("Dropdown Value>> " + $('commonRTSelect').getValue());
}
catch(e) {
alert(e);
}
}
</script>
</body>
</html>
当我调试这个问题时,我发现选择标签的类型是 DispHTMLWndSelectElement。无法在此处附上屏幕截图..
【问题讨论】:
-
只需使用“commonRTSelect.value”,它适用于任何地方。或者,如果你想要 >1,commonRTSelect.querySelectorAll(":checked")
-
感谢您的回复。但为什么它只在县用户登录时失败?该页面在同一台机器上同一 IE9 浏览器的管理员登录中运行良好。什么实际上可能导致此类错误?为什么 MSHTML 互操作会改变它的工作方式,仅在非管理员登录时将此类对象返回给我?
-
有人可以帮忙吗?
标签: javascript html internet-explorer-9 prototypejs