Jquery中对radiobutton、checkbox、dropdownlist等一些基本操作总结

最近在写一些JS,但苦于这些东西不是每次都要用,经常容易忘记,搞的每次都要去网上搜集资料,现记下来以备不时之需:

radiobutton:

<input id="sc" type="radio" name="Type" value="Service Component" οnclick="typeChange()">Service Component	  
<input id="tenant" type="radio" name="Type"  value="Tenant" οnclick="typeChange()">Tenant
 

1、获取某个radio选中的值,有三种方法

$("input:radio:checked").val()(*我最喜欢)  ;

 $("input[type='radio']:cheked").val()   ; 

 $("input[name='Type']:checked").val().

2、后台会根据名字获取相应的选中radio的值,用request.getParameter("Type")

3、设置第一个radio为选中$("input:radio:first").attr("checked","true")

4、设置最后一个radio为选中$("input:radio:last").attr("checked","true")

5、根据索引值设置任意一个radio为选中值$("input:radio").eq(索引值).attr("checked",true)或者           $("input:radio").slice(1,2).attr("checked","true")

6、根据value的值设置选中的radio:$("input[value=Tenant]").attr("checked",true)

7、删除第几个radio:$("input:radio").eq(索引值).remove()   (索引值0,1,2...)

8、遍历$("input:radio").each(index,domEle){}

dropDownList

<select name="uiType" class="ecv_selectFld"  id="uiType_id" style="color: rgb(0, 0, 0); cursor: pointer;width: 145px;" onChange="uiTypeChange()">
	<option value="-1">--- Please Select ---</option>
        <option value="extension field">extension field</option>
        <option value="dynamic menu">dynamic menu</option>
</select>
 

1、获取某个选中的值:

$("select[name=serviceComponent]").val()  

$("#uiType_id").find('option:selected').val()(*我最喜欢)

$("select#uiType_id option:selected").val()  

2、获取当前选中的索引值$("select#uiType_id ").get(0).selectedIndex

3、获取当前的长度$("select#uiType_id ").options.length

4、后台获取根据name  :request.getParameter("uiType")

checkBox:

<input type="checkbox" value="1" name="__row_of_commonSearchResult">
<input type="checkbox" value="2" name="__row_of_commonSearchResult">
<input type="checkbox" value="3" name="__row_of_commonSearchResult">
 

1、后台获取选中的值:request.getParameterValues("__row_of_commonSearchResult");

2、$("input[name=__row_of_commonSearchResult | type=checkbox]").attr("checked","true")


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值