
正文
jquery选中单选框,jq设置单选框选中
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
jQuery获取选中单选框的值为什么每次都只能得到第一次选中的值
你获取的值的方法之前有没有见触发的条件?比如blur?focus?click?等等。如果没有的话
他只会页面刚加载的时候执行一次
,
所以就只能获得一次值了。
相关问答
Q1: 怎么在jQuery的单选框被选,其他单选框就取消被选
单选框的选中与取消与JQuery没有直接关系。只需要设置radio的name值就可以了,相同name值的radio的定义中,是不能有两个同时被选中的。
input type="radio" id="1" name="rd_Grame"
input type="radio" id="2" name="rd_Grame"
input type="radio" id="3" name="rd_Grame"
input type="radio" id="4" name="rd_Grame"
input type="radio" id="5" name="rd_Grame"
这些radio的选中状态是相斥的,也就是只能有一个被选中。当你选中一个,再点击其他未被选中的radio是,之前被选中的就会自动取消选中状态了。
如果有多组,可以给不同的组设置不同的name值,比如
性别:
input type="radio" id="1" name="rd_Grame" 男
input type="radio" id="2" name="rd_Grame" 女
爱好:
input type="radio" id="3" name="rd_Fav" 台球
input type="radio" id="4" name="rd_Fav" 足球
input type="radio" id="5" name="rd_Fav" 乒乓球
Q2: 如何使用jquery给单选框添加选中状态
$('单选元素').prop('checked',true);
如果是一组的话,可以使用:eq或者.eq()指定具体哪个元素
Q3: jquery 如何获取单选框的值
获取单选框的值有三种方式:
1、$('input:radio:checked').val();
2、$("input[type='radio']:checked").val();
3、$("input[name='rd']:checked").val();
Q4: 怎样用jquery使单选框被选中
if($("radio").attr("checked")){
alert("选中")
}else{
alert("不选中")
}
Q5: jquery单选框
!DOCTYPE html
html lang="en"
head
meta charset="UTF-8"
meta name="viewport" content="width=device-width, initial-scale=1.0"
meta http-equiv="X-UA-Compatible" content="ie=edge"
titleDocument/title
script src=""/script
/head
body
p
label for="radio_a"A/label
input type="radio" name="edit" id="radio_a" value=""
input type="text" disabled /
/p
p
label for="radio_b"B/label
input type="radio" name="edit" id="radio_b" value=""
input type="text" disabled /
/p
script async defer
$(document).ready(function() {
$('input[type="radio"]').change(function(e) {
var self = this
$('input[type="text"]').prop('disabled', true)
$(self).next().prop('disabled', false)
$(self).next().focus()
})
})
/script
/body
/html







