<script language="javascript">
function validateadd()
{
var New=documentgetElementsByName("New");
var strNew;
for(var i=0;i<Newlength;i++)
{
if(Newitem(i)checked){
strNew=Newitem(i)getAttribute("value");
break;
}else{
continue;
}
}
if(strNew=="否")
{
alert("商品必须为新品!");
return false;
}
}
</script>
看看这个吧 肯定Ok
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<script src=""></script>
<script>
$(function() {
$("#test")click(function() {
var val = $('input:radio[name="list"]:checked')val();
if(val == null) {
alert("什么也没选中!");
return false;
} else {
alert(val);
}
});
})
</script>
</head>
<body>
<div>
<input type="radio" name="list" value="十分满意" />十分满意
<input type="radio" name="list" value="满意" />满意
<input type="radio" name="list" value="不满意" />不满意
<input type="radio" name="list" value="非常差" />非常差
</div>
<div>
<button id="test">测试</button>
</div>
</body>
</html>
注意:jquery 的引用自己写上,百度知道,有时候不让放
<div>
<label><input id="myRadio" type="radio" value="我的Radio的值" />这是一个Radio</label>
<br/>
<button onclick="saveRadioValue()">保存Radio的值到cookie</button>
<script type="text/javascript">
function saveRadioValue()
{
var rad = documentgetElementById('myRadio');
var radval = radgetAttribute('value');
var cookiename = 'radiovalue';
alert(radval);
writeCookie(cookiename, radval);
alert(readCookie(cookiename)); //测试打印cookie里面的值
}
function writeCookie(name, value, hours) {
var expire = "";
hours = hours || 100;
if (hours != null) {
expire = new Date((new Date())getTime() + hours 3600000);
expire = "; expires=" + expiretoGMTString();
}
documentcookie = name + "=" + escape(value) + expire;
}
function readCookie(name) {
var cookieValue = "";
var search = name + "=";
if (documentcookielength > 0) {
offset = documentcookieindexOf(search);
if (offset != -1) {
offset += searchlength;
end = documentcookieindexOf(";", offset);
if (end == -1) end = documentcookielength;
cookieValue = unescape(documentcookiesubstring(offset, end))
}
}
return cookieValue;
}
</script>
</div>
html 代码:
<form action="indexphp" method="post"><!--get方法也是可以的--!><input type="radio" name="sex" value="f"> 女
<input type="radio" name="sex" value="m"> 男
<input type="submit" name="submit" value="提交">
</form
两个radio控件的name属性必须是一样的
indexphp代码:
$_POST['sex'];//就是单选框选中的 如果使用的是get方法,那么使用 $_GET['sex'];上面的只是简单地例子,可以参考一下
没看到input 有这种写法,你可以这样,
<input type="radio" name="appointmentRadio" value="1"><span>aa</span>
<input type="radio" name="appointmentRadio" value="2"><span>bb</span>
选择了一个radio那么文本值就是$(":radio:checked + span")text();
1获取选中值,三种方法都可以:
$('input:radio:checked')val();
$("input[type='radio']:checked")val();
$("input[name='rd']:checked")val();
2设置第一个Radio为选中值:
$('input:radio:first')attr('checked', 'checked');
或者
$('input:radio:first')attr('checked', 'true');
注:attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)
3设置最后一个Radio为选中值:
$('input:radio:last')attr('checked', 'checked');
或者
$('input:radio:last')attr('checked', 'true');
4根据索引值设置任意一个radio为选中值:
$('input:radio')eq(索引值)attr('checked', 'true');索引值=0,1,2
或者
以上就是关于js怎么获取radio的值全部的内容,包括:js怎么获取radio的值、jquery怎么获取radio选中的值、JavaScript 中如何读取 Radio 中的值并储存在cookie 急 前辈帮帮忙等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)