联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

Jquery操作radio的简单实例 - Web前端

作者:98wpeu发布时间:2026-06-25分类:网页前端技术浏览:5


导读:<inputname="study"type="radio"value="jQuery插件教程">JQuery插件教程<inputname="study"...

<input name="study" type="radio" value="jQuery插件教程">JQuery插件教程
<input name="study" type="radio" value="jQuery学习">jquery学习
<input name="study" type="radio" value="PHP学习">php学习
<input id="tijiao" type="button" value="确定">
<input id="set_jqeury_study" title="JQuery学习" type="button" value="将radio设定为Jquery学习">
<input name="study" type="text" value="请输入您想学到的知识">
<input id="view_input_text" type="button" value="点击我,查看到的是同样名为‘study',但是类型是TEXT的输入框里面的值">

在上面的html代码中,细心的您应该可以发现3个radio的name属性和一个text的name属性都是“study”
复制代码 代码如下:
$(function(){
$('#tijiao').click(function(){
if ($("input:[name=study]:radio:checked").length == 0){
alert("请选择您想学习的知识");
returnfalse;
}
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对象。

标签:实例操作简单WebradioJquery


网页前端技术排行
最近发表
网站分类
标签列表