jQuery获取radio选中项checked的几种方法

如何知道radio哪个选项被选中了,也就是获取checked的radio项。这是个很简单的任务,这里我总结了几个常用的方法,体验一下jQuery的灵活。

具体的 HTML 和 jQuery 代码可以右键查看本页源代码,这里贴一下代码:

HTML:name值一定要相同,四个单选也是一样的

<input type="radio" name="11" value="开">开
<input type="radio" name="11" value="关">关

JQ:  

$(document).ready(function(){
	
	$("#btn_1").click(function(){
		alert($('.radio:checked').val());
	});
	
	$("#btn_2").click(function(){
		alert($('input[type^=radio]:checked').val());
	});
	
	$("#btn_3").click(function(){
		alert($('.radio').filter(':checked').val());
	});
	
	$("#btn_4").click(function(){
		$('.radio').each(function(){  
			if($(this).is(":checked")){  
				alert($(this).val()+" 选中");  
			}else{  
				alert($(this).val()+" 没选中");  
			}  
		})  
	});

});

 本文转载自:http://www.nowamagic.net/academy/detail/23250833 

原文地址:https://www.cnblogs.com/mmzuo-798/p/7120137.html