只是在一些小页面上工作,作为一个更大项目的元素,我对我当前的问题完全感到困惑,这是我的代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<STYLE TYPE="text/css">
.questionBlock { font-size: x-large; color: red }
</STYLE>
<script type="text/javascript">
$(document).ready(function() {
alert("sdsd")
$("input[@name='questionType']").change(function(){
alert("dfdfdf");
var selected = $("form input:radio:checked").val();
alert(selected);
})
});
</script>
<form action="">
<input type="radio" name="questionType" value="closed" /> Closed Endeded<br />
<input type="radio" name="questionType" value="matrix" /> Matrix Question<br />
<input type="radio" name="questionType" value="open" /> Open Ended
</form>
<div class="questionBlock" id="closed">lol</div>
<div class="questionBlock" id="open">rol</div>
<div class="questionBlock" id="matrix">bol</div>
但是无论浏览器如何,更改事件都不会触发,我也尝试过使用绑定(bind),但它让我陷入困境!
最佳答案
jQuery attribute selectors不需要 @ 前缀(如 XPath)。像这样更改您的代码:
$("input[name='questionType']").change(function(){
Here是一个工作版本。
关于javascript - jQuery .change() 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5193445/