当我检查单选按钮但我的代码无效时,我正在尝试提醒某些内容。有谁知道为什么?
<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 :(得分:1)
删除名称选择器中的@
。 JQuery使用CSS选择器,格式如下:
•elementselector[attribute=value]
请改用以下选择器之一:
input[name=crkbrd]
input[name="crkbrd"]
input[name='crkbrd']
运行代码时应该收到此错误消息:
Syntax error, unrecognized expression: [@name='crkbrd']