iframe 中的单选按钮检查
我有 javascript,它位于 iframe 中。当我检查 iframe 中的单选按钮时,父窗口会更改值。它在 firefox 上运行得很好,但在 IE 上却不行...有人能帮我解决这个问题吗?
<script type="text/javascript">
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}
function asd(){
var qwer = getCheckedValue(document.forms['uas'].elements['icon']);
window.parent.document.forms['register'].lang.value = qwer;
window.parent.document.getElementById("images").getElementsByTagName("img")[0].src = "images/lang/" + qwer + ".png";
}
</script>
<form name="uas" method="GET" action="" onchange="asd();">
<label id="1"><input type="radio" name="icon" value="1">One</label><br><label id="2"><input type="radio" name="icon" value="2">Two ...
I have javascript, which is in iframe. When i check radio button in iframe, on parent window change value. It working perfect on firefox, but not on IE... Can someone help me with this problem?
<script type="text/javascript">
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}
function asd(){
var qwer = getCheckedValue(document.forms['uas'].elements['icon']);
window.parent.document.forms['register'].lang.value = qwer;
window.parent.document.getElementById("images").getElementsByTagName("img")[0].src = "images/lang/" + qwer + ".png";
}
</script>
<form name="uas" method="GET" action="" onchange="asd();">
<label id="1"><input type="radio" name="icon" value="1">One</label><br><label id="2"><input type="radio" name="icon" value="2">Two ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码的问题是附加到表单元素的 onchange 事件,IE 不支持此。相反,您必须为每个单选按钮使用 onchange 事件:
或者,您可以使用 Javascript 自动添加事件侦听器。
另外这一行:
是不正确的, getElementById 已经返回您需要的图像,因此 getElementById("images").src = ... 就可以了。
The problem with your code is the onchange event attached to the form element, IE does not support this. Instead, you have to use onchange event for each of the radio buttons:
Alternatively, you can use Javascript to add the event listener automatically.
Also this line:
is not right, getElementById already returns the image you need so getElementById("images").src = ... will do the trick.