http://hi.baidu.com/wanyujun/item/435822137022a7011894ec80
来源:互联网 发布:淘宝假发多少钱 编辑:程序博客网 时间:2024/06/14 12:57
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);
})
})
- http://hi.baidu.com/wanyujun/item/435822137022a7011894ec80
- http://hi.baidu.com/yingshuishui1/item/c6a1610ad1b4851bebfe3870
- http://hi.baidu.com/luckystreet/item/c4a6f10c417db2f1a11034ec
- http://hi.baidu.com/3582077/item/e1ae928ba93b8c55e63d190a
- http://hi.baidu.com/heyg/blog/item/9ca8dcc4785706cb38db4937.html
- http://hi.baidu.com/suwey/blog/item/9b4d72c238e7e334e5dd3bc0.html
- http://hi.baidu.com/lhcling/blog/item/0e3e60cfa55aca3ef8dc61c0.html
- http://hi.baidu.com/jmugis/blog/item/ad03b11f89a25ef6e1fe0b18.html
- http://hi.baidu.com/nnffnn/blog/item/e84cd15c1d893943faf2c07c.html
- http://hi.baidu.com/herowzz/blog/item/286e3c546eb23157574e0077.html
- http://hi.baidu.com/kacaca/blog/item/1fd412d644f9f42907088b89.html
- http://hi.baidu.com/sophie198384/blog/item/26960501e9a757021d9583a0.html
- http://hi.baidu.com/123az/blog/item/f482f51980e8e04642a9ad6c.html
- http://hi.baidu.com/zonesky/blog/item/328d9807043c2ccb7a894717.html
- http://hi.baidu.com/shasha1918/blog/item/ee5fdf18f049fc0235fa4187.html
- http://hi.baidu.com/620734263/blog/item/513a102fa4a551424ec226f8.html
- http://hi.baidu.com/jisu3d/blog/item/f7ad4fd0ac727526960a1652.html HLSL
- http://hi.baidu.com/jsjlx2004/blog/item/74409ccbd5741619be09e6a1.html
- ThinkPHP项目加define("APP_DEBUG",true)后无法加载模块的问题
- 线段树入门( 转 )
- 牛!3D打印机打出人工关节 帮2岁小女孩摆脱病痛
- 查看linux服务器硬盘IO读写负载
- 嵌入未来
- http://hi.baidu.com/wanyujun/item/435822137022a7011894ec80
- W5300E01-ARM用户手册版本1.0(四)
- ui designer tools collection
- 50个对电子商务零售商有价值的建议
- 【转】经典的01背包问题
- 【最小生成树】神母牛的实验
- 编程珠玑第十二章 生成有序随机序列
- How To Access Forms Directly In Oracle Applications R12 [ID 552301.1]
- HDU 1525 Euclid's Game (博弈)