使用 jquery 在收音机上单击或更改事件 [英] click or change event on radio using jquery
本文介绍了使用 jquery 在收音机上单击或更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的页面上有一些无线电,我想在检查的无线电更改时做点什么,但代码不适用于IE:
I have some radios in my page,and I want to do something when the checked radio changes,however the code does not work in IE:
$('input:radio').change(...);
谷歌搜索后,人们建议改用点击.但它不起作用.
And after googling,people suggest use the click instead. But it does not work.
这是示例代码:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$('document').ready(
function(){
$('input:radio').click(
function(){
alert('changed');
}
);
}
);
</script>
</head>
<body>
<input type="radio" name="testGroup" id="test1" />test1<br/>
<input type="radio" name="testGroup" id="test2" />test2<br/>
<input type="radio" name="testGroup" id="test3" />test3</br>
</body>
</html>
它在 IE 中也不起作用.
It also does not work in IE.
所以我想知道发生了什么?
So I want to know what is going on?
如果我单击选中的收音机,我担心它是否会重新触发更改事件?
Also I am afraid if it will retrigger the change event if I click a checked radio?
更新:
我无法添加评论,所以我在这里回复.
I can not add comment,so I reply here.
我使用的是 IE8,而 Furqan 给我的链接在 IE8 中也不起作用.不知道为什么……
I use IE8 and the link Furqan give me also does not work in IE8. I do not know why...
推荐答案
这段代码对我有用:
$(function(){
$('input:radio').change(function(){
alert('changed');
});
});
这篇关于使用 jquery 在收音机上单击或更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文