开发者

Jquery Mobile - Radio group change

开发者 https://www.devze.com 2023-03-01 07:51 出处:网络
I am sure I am missi开发者_StackOverflow社区ng something very obvious, as I new to Jquery. I am using Jquery Mobile with the following markup:

I am sure I am missi开发者_StackOverflow社区ng something very obvious, as I new to Jquery. I am using Jquery Mobile with the following markup:

<div>
    <input data-theme="c" type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" />
    <label for="radio-choice-1">Option 1</label>
</div>
<div>
    <input data-theme="c" type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2"  />
    <label for="radio-choice-2">Option 2</label>
</div>
<div>
    <input data-theme="c" type="radio" name="radio-choice-1" id="radio-choice-3" value="choice-3"  />
    <label for="radio-choice-3">Option 3</label>
</div>

and I am trying to perform an action when the value changes.

So I have:

$(":input[@name='radio-choice-1']").change(function() {
        alert('clicked');
});

Now the first time I select an option, the event doesn't fire. It does fire when I subsequently change it (i.e. the 2nd, 3rd etc. time) but not the first. I assume it is because it not being 'changed' per se, just given a value. I tried to changing it to click but then it never fires.

What am I missing here? Any help much appreciated.


Live Example: http://jsfiddle.net/wWFGf/2/

Alternate HTML Syntax: http://jsfiddle.net/wWFGf/3/

$("[name=radio-choice-1]").change(function() {
    alert('Selected: '+$('input[name=radio-choice-1]:checked').val());
});


I think this will help

$(document).ready(function() {

$(":input[@name='radio-choice-1']").live('change mousedown',function(event) { 
        alert('clicked'); 
}); 

});

Working example here http://jsfiddle.net/XVuAs/1/


$('input[type="radio"]').change( function() {
        alert('clicked');
});

Above code, tested and working fine for me...


If you dynamically load the page you might need to do something like this:

$('input[type="radio"]').live('changed' function() {
alert('clicked live');  
});
0

精彩评论

暂无评论...
验证码 换一张
取 消