jQuery取得/设置select的值
本来以为jQuery("#select1").val();是取得选中的值,
那么jQuery("#select1").text();就是取得的文本。
这是不正确的,正确做法是:
jQuery("#select1 option:selected").text();
同样的,设置select的value的做法是:
$("#select1 option:selected").attr("value", 'aaa');
或:$("#select1 option:selected").val('aaa');
jQuery取得/设置select的值的更多相关文章
- 如何用原生js或jquery设置select的值
1.原生js设置select值的方法 (1)有时可能需要隐藏select,但是还得需要更改select所传递的值.(select的默认选中之为第一个,即下标为0的选项值) var gd2=docume ...
- 设置select默认值
W3C下设置一个默认值直接为 select.value='默认值'. IE8下设置默认值必须有这个option才能被设置,不像W3C 如chrome这种,直接设置就能显示,如果IE下这样设置的话sel ...
- jquery 设置select 默认值
$('#@(Perfix)OrgType').children("option").each(function () { var temp_value = $(this).val( ...
- Jquery 获取 radio/select选中值
Radio <input type="radio" name="rd" id="rd1" checked="checked& ...
- jquery easyui校验select下拉列表值是否为空的问题
属性名 类型 描述 默认值 required 布尔 定义文本域是否为必填项 false validType 字符串 定义字段的验证类型,比如email, url, etc. null missingM ...
- html 设置Select options值进行绑定
<select id="cdms"> <option value="">请选择...</option> <option ...
- jquery操作select(取值,设置选中)
最近工作中总出现select 和 option问题,整理一下,内容大部分源于网络资料 一.基础取值问题 例如<select class="selector"></ ...
- jquery操作select(取值,设置选中) 基础
每一次操作select的时候,总是要出来翻一下资料,不如自己总结一下,以后就翻这里了. 比如<select class="selector"></select&g ...
- jQuery radio取值,checkbox取值,select取值
语法解释: $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 var checkTex ...
随机推荐
- the art of seo(chapter one)
preface:Andy Johns (@ibringtraffic):growth strategist@Wealthfront ***1.Search Reflecting Consciousne ...
- hdu-4989 Summary(水题)
题目链接: Summary Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) P ...
- 【C/C++】产生随机数
#include<iostream> #include<Ctime> #include<Cstdlib> using namespace std; //产生n个st ...
- Android-Styles and Themes [From API Guide]
This blog was opened 5 months ago and it has 57 posts now,but the poor thing is by now no one has co ...
- 卸载asterisk 会装就要会卸载 你会吗? [跟我一起学](转安静的发狂者)
1 针对用编译的方式安装时的卸载 第一步 :先停止你的asterisk >asterisk -rx ‘stop now’然后要验证一下是否真的被停了. >ps aux|grep “as ...
- HDU1525 Euclid's Game
Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtra ...
- Unix高级环境编程
[07] Unix进程环境==================================1. 进程终止 atexit()函数注册终止处理程序. exit()或return语句: ...
- HDU1203(01背包变形)
I NEED A OFFER! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u D ...
- Flutter实战视频-移动电商-16.补充_保持页面状态
16.补充_保持页面状态 修正一个地方: 设置了item的高度为380 横向列表为380.最终build的高度也增加了50为430. 增加了上面的高度以后,下面那个横线划掉的价格可以显示出来了. 但是 ...
- 新浪微博分享出现libc++abi.dylib: terminating with uncaught exception of type NSException微博微信SDK运行编译报错
SDK出现libc++abi.dylib: terminating with uncaught exception of type NSException 的问题: 解决方法 结合 # 监测bug( ...