How can I simulate a click on a jQuery UI radio button?

后端 未结 3 1764
花落未央
花落未央 2021-02-19 23:27

I have some radio buttons

&l
相关标签:
3条回答
  • I believe you're looking for the select event.

    $("input[value='"+data.chartype+"']").select();
    
    0 讨论(0)
  • 2021-02-20 00:01
    <div class="radioVote">
    <input type="radio" id="radio1" name="radio" value="1"/><label for="radio1">ONE</label>
    <input type="radio" id="radio2" name="radio" value="2"/><label for="radio2">TWO</label>
    </div> 
    
    
    
    $(document).ready(function(){
    
            $( ".radioVote" ).buttonset();
    
            $('[for^=radio]').click(function() {
                var theRadioElement = $(this).prev();
                alert("Button" + theRadioElement.attr('id') + " clicked. VALUE:" + theRadioElement.val());
            });
    
        });
    

    This example shows how to get the ID and Value when you click on a label that belongs to a jQueryUI radio.

    Happy coding :)

    0 讨论(0)
  • 2021-02-20 00:23

    You have to do it with the label element added by jQuery UI. Try:

    $("label[for='character_chartype_"+data.chartype+"']").click();
    

    Have a look at it here, in a controlled environment: http://jsfiddle.net/B3d4z/

    0 讨论(0)
提交回复
热议问题