http://hi.baidu.com/wanyujun/item/435822137022a7011894ec80
jquery獲得select option的值 和對select option的操作
獲取Select :
獲取select 選中的 text :
$("#ddlRegType").find("option:selected").text();
獲取select選中的 value:
$("#ddlRegType ").val();
獲取select選中的索引:
$("#ddlRegType ").get(0).selectedIndex;
設定select:
設定select 選中的索引:
$("#ddlRegType ").get(0).selectedIndex=index;//index為索引值
設定select 選中的value:
$("#ddlRegType ").attr("value","Normal“);
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;
設定select 選中的text:
var count=$("#ddlRegType option").length;
for(var i=0;i<count;i++)
{ if($("#ddlRegType ").get(0).options[i].text == text)
{
$("#ddlRegType ").get(0).options[i].selected = true;
break;
}
}
$("#select_id option[text='jQuery']").attr("selected", true);
設定select option項:
$("#select_id").append("<option value='Value'>Text</option>"); //新增一項option
$("#select_id").prepend("<option value='0'>請選擇</option>"); //在前面插入一項option
$("#select_id option:last").remove(); //刪除索引值最大的Option
$("#select_id option[index='0']").remove();//刪除索引值為0的Option
$("#select_id option[value='3']").remove(); //刪除值為3的Option
$("#select_id option[text='4']").remove(); //刪除TEXT值為4的Option
清空 Select:
$("#ddlRegType ").empty();
jquery獲得值:
.val()
.text()
設定值
.val('在這裡設定值')
$("#btn1").click(function(){
$("[name='checkbox']").attr("checked",'true');//全選
})
$("#btn2").click(function(){
$("[name='checkbox']").removeAttr("checked");//取消全選
})
$("#btn3").click(function(){
$("[name='checkbox']:even").attr("checked",'true');//選中所有奇數
})
$("#btn4").click(function(){
$("[name='checkbox']").each(function(){//反選
if($(this).attr("checked")){
$(this).removeAttr("checked");
}
else{
$(this).attr("checked",'true');
}
})
})
$("#btn5").click(function(){//輸出選中的值
var str="";
$("[name='checkbox'][checked]").each(function(){
str+=$(this).val()+"\r\n";
//alert($(this).val());
})
alert(str);
})
})
相關文章
- JavaScript item()JavaScript
- FileList item()
- sticky list item
- item_get
- CSSStyleDeclaration.item()方法CSS
- RecyclerView增刪itemView
- Item點選水波紋效果
- [Blue Prism] Data item 的使用
- 對RecyclerView Item做動畫View動畫
- 工作294:for[item.key]使用
- item2 新增多個 SSH
- item的介紹與使用-2.0
- ListView項(Item)的三種佈局View
- implicit declaration of item ‘write’; did him mean ‘fwrite’?
- [LeetCode] 2070. Most Beautiful Item for Each QueryLeetCode
- Android recyclerview刪除item重新整理列表AndroidView
- Scrapy框架的使用之Item Pipeline的用法框架
- item_review - 獲得淘寶評論View
- item_get_app資料返回結果APP
- python argument 1 must be 2-item sequence, not intPython
- PyQt5刪除QListWidget中的itemQT
- OpenCL 增強單work-item kernel效能策略
- item_search - 按關鍵字搜尋商品
- http://192.168.1.1/ http://3232235777/HTTP
- 使用RecyclerView動態改變item時遇到的坑View
- elment UI 表格 item 驗證問題解決方案UI
- Granting and Managing Item Level Permission using SharePoint2013 Designer Workflow
- 使用介面實現RecyclerView中的item點選事件View事件
- HTTP、HTTP1.1、HTTP/2的區別HTTP
- HTTP協議之:HTTP/1.1和HTTP/2HTTP協議
- http,https, http2.0HTTP
- 你不知道的JavaScript--Item1 嚴格模式JavaScript模式
- antd表單的<a-form-item>使用自定義label插槽ORM
- 05 前端HTTP協議(圖解HTTP) 之 HTTP首部前端HTTP協議圖解
- [計算機網路]HTTP 1.0/HTTP 1.1/HTTP 2.0計算機網路HTTP
- HTTP1.1、HTTP2、HTTP3 演變HTTP
- http http headers參考文件HTTPHeader
- 03 前端HTTP協議(圖解HTTP) 之 HTTP報文內的HTTP資訊前端HTTP協議圖解
- HTTP協議圖文簡述--HTTP/HTTPS/HTTP2HTTP協議