如何模拟对jQuery UI单选按钮的点击? [英] How can I simulate a click on a jQuery UI radio button?
本文介绍了如何模拟对jQuery UI单选按钮的点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些单选按钮
<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按钮
that I turn into jQuery UI buttons
$("#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.
推荐答案
您必须使用标签
元素通过jQuery UI添加。尝试:
You have to do it with the label
element added by jQuery UI. Try:
$("label[for='character_chartype_"+data.chartype+"']").click();
在受控环境中查看它: http://jsfiddle.net/B3d4z/
Have a look at it here, in a controlled environment: http://jsfiddle.net/B3d4z/
这篇关于如何模拟对jQuery UI单选按钮的点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文