jquery 获取radio的选中事件,radio默认选中时,显示其中一行tr,选中另外一个radio时,显示不同的tr记录

jquery 获取radio的选中事件,radio默认选中时,显示其中一行tr,选中另外一个radio时,显示不同的tr记录,第1张

首先添加给radio添加绑定单击事件,可以直接使用onclick="",也可以用jquery绑定;

$(function() {

showCont()

$("input[name=price_type]").click(function() {

showCont()

})

})

function showCont(){

var normal = document.getElementById("price_type1")

var special = document.getElementById("price_type2")

if (normal.checked) {

$("#sellInfo2").hide()

$("#sellInfo1").show()

}

if (special.checked) {

$("#sellInfo1").hide()

$("#sellInfo2").show()

}

}

结果:

你的$("input[name=jizai]")这个选择器会获得两个radio对象,都设置选中,只能最后一个是被选中的,因为是单选。

如果你要这么写,可以指定索引,

如:$("input[name=jizai]:eq(0)").attr("checked",'checked')这样就是第一个选中咯。

jquery中,radio的选中与否是这么设置的。

$("#rdo1").attr("checked","checked")

$("#rdo1").removeAttr("checked")

还有问题hi我哦。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11665717.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存