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 ...
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:
<label id="1"><input type="radio" name="icon" value="1" onchange="asd();">One</label>
<label id="2"><input type="radio" name="icon" value="2" onchange="asd();">Two</label>
Alternatively, you can use Javascript to add the event listener automatically.
Also this line:
window.parent.document.getElementById("images").getElementsByTagName("img")[0].src = "images/lang/" + qwer + ".png";
is not right, getElementById already returns the image you need so getElementById("images").src = ... will do the trick.
精彩评论