I have some radio buttons
我有一些单选按钮
<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>
that I turn into jQuery UI buttons
我转向jQuery UI按钮
$("#typeRadios").buttonset();
What line of code can I use to simulate a click on one of the buttons? I've tried this
我可以使用哪一行代码来模拟其中一个按钮的点击?我试过这个
// here data.chartype equals "A"
$("input[value='"+data.chartype+"']").click();
but it doesn't work. Thanks for reading.
但它不起作用。谢谢阅读。
3 个解决方案
#1
6
You have to do it with the label
element added by jQuery UI. Try:
你必须使用jQuery UI添加的label元素。尝试:
$("label[for='character_chartype_"+data.chartype+"']").click();
Have a look at it here, in a controlled environment: http://jsfiddle.net/B3d4z/
在这里,在受控环境中查看它:http://jsfiddle.net/B3d4z/
#2
1
I believe you're looking for the select
event.
我相信你正在寻找精选活动。
$("input[value='"+data.chartype+"']").select();
#3
0
<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.
此示例显示了在单击属于jQueryUI无线电的标签时如何获取ID和值。
Happy coding :)
快乐编码:)
#1
6
You have to do it with the label
element added by jQuery UI. Try:
你必须使用jQuery UI添加的label元素。尝试:
$("label[for='character_chartype_"+data.chartype+"']").click();
Have a look at it here, in a controlled environment: http://jsfiddle.net/B3d4z/
在这里,在受控环境中查看它:http://jsfiddle.net/B3d4z/
#2
1
I believe you're looking for the select
event.
我相信你正在寻找精选活动。
$("input[value='"+data.chartype+"']").select();
#3
0
<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.
此示例显示了在单击属于jQueryUI无线电的标签时如何获取ID和值。
Happy coding :)
快乐编码:)