`

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

 
阅读更多

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

radiobutton:

<input id="sc" type="radio" name="Type" value="Service Component" onclick="typeChange()">Service Component	  
<input id="tenant" type="radio" name="Type"  value="Tenant" onclick="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")


 

分享到:
评论
1 楼 无赖二号 2015-11-04  
3333[color=red][/color]

相关推荐

Global site tag (gtag.js) - Google Analytics