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('在这里设置值')
$("document").ready(function(){
$("#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://www.cnblogs.com/summer_adai/archive/2012/12/01/2797145.html
jquery获得select option的值 和对select option的操作【转藏】的更多相关文章
- jquery获得select option的值 和对select option的操作
jQuery获取Select元素,并选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Se ...
- jquery获得select option的值和对select option的操作
<body> <select name="month" id="selMonth" onchange="set()"> ...
- select 获取选中option的值方法,选中option方法
options=$("#Select option:selected"); options.attr('name');options.val(); options.text(); ...
- Jquery操作select,左右移动,双击移动 取到所有option的值
$(function () { function MoveItem(fromId, toId) { $("#" + fromId + " option:selected& ...
- jQuery获取Radio选择的Value值||两个select之间option的互相添加操作(jquery实现)
jQuery获取Radio选择的Value值: 1. $("input[name='radio_name'][checked]").val(); //选择被选中Radio的Val ...
- jquery获得option的值和对option进行操作
Query获取Select元素,并选择的Text和Value: $("#select_id").change(function(){//code...}); //为Select添加 ...
- jquery获得option的值和对option进行操作 作者: 字体:[增加 减小] 类型:转载 时间:2013-12-13 我要评论
jquery获得option的值和对option进行操作 作者: 字体:[增加 减小] 类型:转载 时间:2013-12-13我要评论 本文为大家介绍下jquery获得option的值和对option ...
- jquery获得option的值(示例)
jquery获得option的值和对option的操作. jQuery获取Select元素,并选择的Text和Value: 复制代码代码如下: $("#select_id").ch ...
- jquery新增,删除 ,修改,清空select中的option
jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selec ...
随机推荐
- 2.6.2 Notification的功能与用法
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...
- 创建用于自定义SharePoint解决方案部署的Visual Studio项目
转:http://soft.zdnet.com.cn/software_zone/2007/0903/488083.shtml 在基于SharePoint的开发中,我们通常会在WSS的TEMPLATE ...
- Gson ------ 实例演习
[本文范围]: 本文并非JSON知识讲解资料,亦非GSON知识讲解资料,而是通过实例让开发人员了解通过Gson如何使Java对象和Json对象进行相互转换. [JSON参考资料]: Json快速入门: ...
- 基础算法(搜索):NOIP 2015 斗地主
Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3& ...
- HDU 2546 饭卡
http://acm.hdu.edu.cn/showproblem.php?pid=2546 呆呆. 饭卡 Time Limit: 5000/1000 MS (Java/Others) Memo ...
- Unity 官方 Demo: 2DPlatformer 的 SLua 版本。
9月份时,趁着国庆阅兵的假期,将 Unity 官方 Demo: 2DPlatformer 移植了一个 SLua 版本,并放在了我的 GitHub 账号下:https://github.com/yauk ...
- make it clear how to use const in C++
1.first of all,take a lookup on the left side of keyword const.If there is something(type or pointer ...
- openstack libtray
OpenStack packages¶ Distributions release OpenStack packages as part of the distribution or using ot ...
- 快捷键Ctrl+c、Ctrl+d、Ctrl+u、Ctrl+a、Ctrl+e
tab:命令或路径补全键 Ctrl +c :终止当前任务命令或程序 Ctrl +d :退出当前用户环境 Ctrl +Shift+c ssh客户端ssh里复制的命令 Ctrl + a到开头 Ctrl ...
- HTML5 Canvas 颜色填充学习
---恢复内容开始--- 如果我们想要给图形上色,有两个重要的属性可以做到:fillStyle 和 strokeStyle. fillStyle = color strokeStyle = color ...