连接到我的change() jQuery 事件的RadioButtons 不触发
这是我的代码:
<script type="text/javascript">
$('input[name="paymenttype"]').change(function () {
alert("works!"); // This doesn't fire.
});
</script>
<div id="paymentselector">
<label>
<input name="paymenttype" value="deposit" type="radio" />Deposito
</label>
<label>
<input name="paymenttype" value="creditcard" type="radio" />Tarjeta de Credito
</label>
</div>
根据文档,这应该有效: http://api.jquery.com/attribute-equals-selector/
在Change() 事件,警报不会被触发。
我的 Javascript 代码有问题吗?
Here's my code:
<script type="text/javascript">
$('input[name="paymenttype"]').change(function () {
alert("works!"); // This doesn't fire.
});
</script>
<div id="paymentselector">
<label>
<input name="paymenttype" value="deposit" type="radio" />Deposito
</label>
<label>
<input name="paymenttype" value="creditcard" type="radio" />Tarjeta de Credito
</label>
</div>
According to the documentation, this should work:
http://api.jquery.com/attribute-equals-selector/
In the change() event, the alert isn't fired.
Is something wrong in my Javascript code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试添加文档就绪处理程序 -
You could try adding a document ready handler -
好吧,马上,您需要将 JS 包装在
$(document).ready(function(){ ... });
块中。当 JS 运行时,它尝试访问的元素还不存在。Well, right off the bat, you need to wrap your JS in a
$(document).ready(function(){ ... });
block. When the JS is run, the element it's trying to access doesn't exist yet.