最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

jQuery的选中方法

来源:动视网 责编:小OO 时间:2020-11-27 20:07:26
文档

jQuery的选中方法

select下拉列表的选中方法是:$(";slect option:eq(1)";).attr(";selected";,true);//选中第二个option。chekbox的选中方法:$(";[value=check1";]:checkbox).attr(";checked";,true)。radio的选中方法:$(";[value=radio2";]:radio).attr(";checked";,true)。以上是简写,重要的是看代码。
推荐度:
导读select下拉列表的选中方法是:$(";slect option:eq(1)";).attr(";selected";,true);//选中第二个option。chekbox的选中方法:$(";[value=check1";]:checkbox).attr(";checked";,true)。radio的选中方法:$(";[value=radio2";]:radio).attr(";checked";,true)。以上是简写,重要的是看代码。


本文主要为大家带来一篇各种选择框jQuery的选中方法(实例讲解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望能帮助到大家。

select下拉列表的选中方法是:$("slect option:eq(1)").attr("selected",true);//选中第二个option

chekbox的选中方法:$("[value=check1"]:checkbox).attr("checked",true);

radio的选中方法:$("[value=radio2"]:radio).attr("checked",true);

以上是简写,重要的是看代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>3-10-4</title>
<style type="text/css">
.test{
 font-weight:bold;
 color : red;
}
.add{
 font-style:italic;
}
</style>
 <!-- 引入jQuery -->
 <script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
 <script type="text/javascript">
 //<![CDATA[
 $(function(){
 //设置单选下拉框选中
 $("input:eq(0)").click(function(){
 $("#single option").removeAttr("selected"); //移除属性selected
 $("#single option:eq(1)").attr("selected",true); //设置属性selected
 });
 //设置多选下拉框选中
 $("input:eq(1)").click(function(){
 $("#multiple option").removeAttr("selected"); //移除属性selected
 $("#multiple option:eq(2)").attr("selected",true);//设置属性selected
 $("#multiple option:eq(3)").attr("selected",true);//设置属性selected
 });
 //设置单选框和多选框选中
 $("input:eq(2)").click(function(){
 $(":checkbox").removeAttr("checked"); //移除属性checked
 $(":radio").removeAttr("checked"); //移除属性checked
 $("[value=check2]:checkbox").attr("checked",true);//设置属性checked
 $("[value=check3]:checkbox").attr("checked",true);//设置属性checked
 $("[value=radio2]:radio").attr("checked",true);//设置属性checked
 });
 });
 //]]>
 </script>
</head>
<body>
 <input type="button" value="设置单选下拉框选中"/>
 <input type="button" value="设置多选下拉框选中"/>
 <input type="button" value="设置单选框和多选框选中"/>

<br/><br/>

<select id="single">
 <option>选择1号</option>
 <option>选择2号</option>
 <option>选择3号</option>
</select>

<select id="multiple" multiple="multiple" style="height:120px;">
 <option selected="selected">选择1号</option>
 <option>选择2号</option>
 <option>选择3号</option>
 <option>选择4号</option>
 <option selected="selected">选择5号</option>
</select>

<br/><br/>


<input type="checkbox" value="check1"/> 多选1
<input type="checkbox" value="check2"/> 多选2
<input type="checkbox" value="check3"/> 多选3
<input type="checkbox" value="check4"/> 多选4

<br/>

<input type="radio" value="radio1" name="a"/> 单选1
<input type="radio" value="radio2" name="a"/> 单选2
<input type="radio" value="radio3" name="a"/> 单选3
</body>
</html>

文档

jQuery的选中方法

select下拉列表的选中方法是:$(";slect option:eq(1)";).attr(";selected";,true);//选中第二个option。chekbox的选中方法:$(";[value=check1";]:checkbox).attr(";checked";,true)。radio的选中方法:$(";[value=radio2";]:radio).attr(";checked";,true)。以上是简写,重要的是看代码。
推荐度:
标签: 方法 选择 选中
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top