jquery设置radio选中

jquery设置radio选中,第1张

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

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

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

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

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

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

还有问题hi我哦。

首先添加给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()

}

}

结果:

使用:$( "#id" ).prop( "checked", true )

$( elem ).attr( "checked" ) 1.6版本前返回值为boolean,

1.6+返回值为string,为属性的实际值,而不是boolean.

新的浏览器返回的是“checked”,老的浏览器返回的是true,所以不能使用attr

.prop()方法被用来处理boolean attributes


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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存