当我选择单选按钮时,我想知道为什么这在IE上无法正常工作?
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("input[name='crkbrd']").change(function(){
if ($("input[name='crkbrd']:checked").val() == 'Upload')
{ alert("Upload Your Own Ad"); }
else if ($("input[name='crkbrd']:checked").val() == 'Edit')
{ alert("Edit Your Ad Here"); }
else
{ alert("You haven't chosen anything"); }
});
});
</script>
</head>
<body>
<input type="radio" id="rb1" name="crkbrd" value="Upload" /> Upload Your Own Ad<br />
<input type="radio" id="rb2" name="crkbrd" value="Edit" /> Edit Your Ad Here
</body>
</html>
答案 0 :(得分:4)
IE有一个单选按钮的错误,因为在单选按钮模糊之前它不会触发更改事件。请改为使用click事件。
错误详情:http://webbugtrack.blogspot.com/2007/11/bug-193-onchange-does-not-fire-properly.html
请注意,此错误已在IE9中修复(只要您在标准模式下运行)
答案 1 :(得分:0)
我在IE 8,Firefox和Chrome浏览器上工作
尝试将单个class
属性分配给单选按钮:
<input type="radio" id="rb1" name="crkbrd" value="Upload" class="myRadio" /> Upload Your Own Ad<br />
<input type="radio" id="rb2" name="crkbrd" value="Edit" class="myRadio" /> Edit Your Ad Here
然后使用以下内容:
$( ".myRadio" ).change( function(){
if ($(this).val() == 'Upload') {
alert("Upload Your Own Ad");
} else
if ($(this).val() == 'Edit') {
alert("Edit Your Ad Here");
} else {
alert("You haven't chosen anything");
}
});