使用 jquery 在收音机上单击或更改事件机上、单击、事件、jquery

由网友(天会亮心会暖i)分享简介:我在我的页面上有一些无线电,我想在检查的无线电更改时做点什么,但代码不适用于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...

我在我的页面上有一些无线电,我想在检查的无线电更改时做点什么,但代码不适用于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');   
    });          

});

http://jsfiddle.net/3q29L/

阅读全文

相关推荐

最新文章