Discuz教程网

jquery获得下拉框值的代码

[复制链接]
authicon dly 发表于 2011-9-10 21:20:01 | 显示全部楼层 |阅读模式
获取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:
  1. $("#ddlRegType ").attr("value","Normal“);
  2. $("#ddlRegType ").val("Normal");
  3. $("#ddlRegType ").get(0).value = value;
复制代码

设置select 选中的text:
  1. var count=$("#ddlRegType option").length;
  2. for(var i=0;i<count;i++)
  3. { if($("#ddlRegType ").get(0).options[i].text == text)
  4. {
  5. $("#ddlRegType ").get(0).options[i].selected = true;
  6. break;
  7. }
  8. }

  9. $("#select_id option[text='jQuery']").attr("selected", true);



  10. 设置select option项: [code]$("#select_id").append("<option value='Value'>Text</option>"); //添加一项option
  11. $("#select_id").prepend("<option value='0'>请选择</option>"); //在前面插入一项option
  12. $("#select_id option:last").remove(); //删除索引值最大的Option
  13. $("#select_id option[index='0']").remove();//删除索引值为0的Option
  14. $("#select_id option[value='3']").remove(); //删除值为3的Option
  15. $("#select_id option[text='4']").remove(); //删除TEXT值为4的Option
复制代码


清空 Select:
$("#ddlRegType ").empty();



上一篇:javascript高级学习笔记整理
下一篇:Jquery中对数组的操作代码
authicon 微博评论 发表于 2011-9-10 21:21:54 | 显示全部楼层
[0]10--00_--0个45块  [帅]

来自 波娥 的新浪微博
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 20:06

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表