Jquery 操作radio实例

Jquery代码

$(function(){
	$('#tijiao').click(function(){
		if ($("input:[name=study]:radio:checked").length == 0){
			alert("请选择您想学习的知识");
			return false;
		}
		var study = $("input:[name=study]:radio:checked").val();
		alert("谢谢!您选择的是" + study);
	})
	$("#set_jqeury_study").click(function(){
		var $button = $(this);
		$("input:[name=study]:radio").each(function(){
			if (this.value == $button.attr('title')){
				this.checked=true;
			}
		})
	})
	$("#view_input_text").click(function(){
		alert($("input[name=study]:text").val());
	})
})

$(“input:[name=study]:radio:checked”)这段代码取得的是所有name属性为“study”而且已经被选中的radio的jquery对象,通过判断他的length 是否等于0,就可以知道这个radio选项是否有一个被选中了。

$(“input[name=study]:text”)这段代码取得的是name属性为“study”的text输入框的jquery对象。

恩~~说的可能大家不太明白~~~呵呵~~我的教程水平还有待提高,不过要是懂jquery的人看的话,应该是没问题的。
恩就这么多了~~

转自:http://woshao.com/article/1e1ba5c40e5d11e0b943000c295b2b8d

原文地址:https://www.cnblogs.com/hinsxun/p/1953194.html