Jquery 在ButtonSet中获取单击的元素
我想知道单击了哪个元素,这样我就可以更改它的CSS类。代码如下:Jquery 在ButtonSet中获取单击的元素,jquery,Jquery,我想知道单击了哪个元素,这样我就可以更改它的CSS类。代码如下: <script type="text/javascript"> $(function() { $("#radio").buttonset(); }); </script> $(函数(){ $(“#收音机”).buttonset(); }); 选择1 选择2 选择3 您可以这样做: $("#radio :radio").click(function(){
<script type="text/javascript">
$(function() {
$("#radio").buttonset();
});
</script>
$(函数(){
$(“#收音机”).buttonset();
});
选择1
选择2
选择3
您可以这样做:
$("#radio :radio").click(function(){
alert($(this).attr("id")); // this refers to current clicked radio button
$(this).removeClass('class_name').addClass('class_name');
});
jqueryevents将
此
作为触发事件的对象返回。所以你只需要检查一下这个
有这组元素的
<div id="radio">
<input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
<input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
<input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
</div>
然后绑定一个事件:
.click(function(e) { });
使用此检索元素:
$("#radio :radio").click(function(e) {
var rawElement = this;
var $element = $(this);
/* Do stuff with the element that fired the event */
});
您可以使用以下方法来操作元素的类。您还可以使用以下方法从按钮集检索选定的单选按钮:
$j("#radioset :radio:checked")
然后对元素执行任何您想要的操作 这部分的意思是什么:
var$element=$(this)代码>?$element
有何不同?你会怎么做?@jeffamaphone这是DOM节点$(this)
是包含DOM节点的jQuery对象我很好奇“$j”是什么意思,或者是打字错误?
$('#radio').buttonset().find(':radio').click(function(e) {
var $radio = $(this);
$radio.addClass('active');
});
.click(function(e) { });
$("#radio :radio").click(function(e) {
var rawElement = this;
var $element = $(this);
/* Do stuff with the element that fired the event */
});
$j("#radioset :radio:checked")
$('#radio').buttonset().find(':radio').click(function(e) {
var $radio = $(this);
$radio.addClass('active');
});