Jquery 对radiobutton采取行动的最短可能方式
我有三个单选按钮Jquery 对radiobutton采取行动的最短可能方式,jquery,Jquery,我有三个单选按钮 <input id="RadioJ" type="radio" name="grp1" class="abc" /> <input id="FaroK" type="radio" name="grp1" class="abc" /> <input id="MartreLK" type="radio" name="grp1" class="abc" /> 哪种方法是实现此目的的最短方法: 如果已选中RadioJ 这样做 否则,
<input id="RadioJ" type="radio" name="grp1" class="abc" />
<input id="FaroK" type="radio" name="grp1" class="abc" />
<input id="MartreLK" type="radio" name="grp1" class="abc" />
哪种方法是实现此目的的最短方法:
如果已选中RadioJ这样做
否则,如果选中FaroK
那样做
否则,如果MartreLK
也许可以做这样那样的事情?(:
var chkd = $("input[name=grp1]:checked").attr("id");
if (chkd === "RadioJ") {
//do this
} else if (chkd === "FaroK") {
//do that
} else if (chkd === "MartreLK") {
//do this and that
} else {
//nothing is checked
}
$(document).ready ( function () {
$(".abc").click ( function (event) {
var target = event.target.id;
if ( id === 'RadioJ' )
{
}
else if ( id === 'FaroK' )
{
}
else if ( id === 'MartreLK' )
{
}
});
});