簡體   English   中英

如何模擬jQuery UI單選按鈕上的單擊?

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

我有一些單選按鈕

<div id="typeRadios">
    <input id="character_chartype_a" name="character[chartype]" type="radio" value="A" /><label for="character_chartype_a">A</label>
    <input id="character_chartype_a" name="character[chartype]" type="radio" value="B" /><label for="character_chartype_b">B</label>
</div>

我轉向jQuery UI按鈕

$("#typeRadios").buttonset();

我可以使用哪一行代碼來模擬其中一個按鈕的點擊? 我試過這個

// here data.chartype equals "A"
$("input[value='"+data.chartype+"']").click();

但它不起作用。 謝謝閱讀。

你必須使用jQuery UI添加的label元素。 嘗試:

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

在這里,在受控環境中查看它: http//jsfiddle.net/B3d4z/

我相信你正在尋找select活動。

$("input[value='"+data.chartype+"']").select();
<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());
        });

    });

此示例顯示如何在單擊屬於jQueryUI無線電的標簽時獲取ID和值。

快樂編碼:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM