dropdownlist中,selectvalue是获取select选中value选中值,请问如何获取select选中value选中项

19142人阅读
源代码(22)
&&td style=&width: 20%&&
&&& &asp:DropDownList ID=&DropdownList1& runat=&server& AutoPostBack=&true& /&
&&input type=&button& id=&btnSubmit& name=&btnSubmit& value=&保存&& onclick=&getvalue();&/&
&&& &script type=&text/javascript&&
function getvalue(){
&&&&&&&&&&&&&&& var select1 = document.all.&%=
DropdownList1.ClientID %&;
&&&&&&&&&&&&&&& var selectvalue = select1.options[select1.selectedIndex].
&&&&&&&&&&&&&&& var selectText= select1.options[select1.selectedIndex].
&&&&&&&&&&&&&& alert(selectvalue+&& &+selectText);
&&& &/script&
其他网上给出的:
&&& &script type=&text/javascript& language=&javascript&&
&&& function SearchChange()
&&&&&&& var ddl = document.getElementById(&DropDownList1&)&&
&&&&&&& var index = ddl.selectedI&&
&&&&&&&&&&&
&&&&&&& var Value = ddl.options[index].&&
&&&&&&& var Text = ddl.options[index].
&&&&&&& alert(Value);
&&& &/script&
方式获取的ddl 为null;
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:159469次
积分:1903
积分:1903
排名:第15142名
原创:24篇
转载:40篇
评论:34条
(2)(1)(1)(2)(2)(6)(1)(4)(8)(5)(4)(2)(1)(1)(3)(2)(1)(1)(1)(9)(3)(1)(1)(1)(2)Jquery操作下拉框(DropDownList)实现取值赋值
字体:[ ] 类型:转载 时间:
Jquery操作下拉框(DropDownList)想必大家都有所接触吧,下面与大家分享下对DropDownList进行取值赋值的实现代码
1. 获取选中项:
代码如下: 获取选中项的Value值: $('select#sel option:selected').val(); 或者 $('select#sel').find('option:selected').val(); 获取选中项的Text值: $('select#seloption:selected').text(); 或者 $('select#sel').find('option:selected').text();
2. 获取当前选中项的索引值:
代码如下: $('select#sel').get(0).selectedI
3. 获取当前option的最大索引值:
代码如下: $('select#sel option:last').attr("index")
4. 获取DropdownList的长度:
代码如下: $('select#sel')[0].options. 或者 $('select#sel').get(0).options.
5. 设置第一个option为选中值:
代码如下: $('select#sel option:first').attr('selected','true') 或者 $('select#sel')[0].selectedIndex = 0;
6. 设置最后一个option为选中值:
代码如下: $('select#sel option:last).attr('selected','true')
7. 根据索引值设置任意一个option为选中值:
代码如下: $('select#sel')[0].selectedIndex =索引值;索引值=0,1,2....
8. 设置Value=4 的option为选中值:
代码如下: $('select#sel').attr('value','4'); 或者 $("select#sel option[value='4']").attr('selected', 'true');
9. 删除Value=3的option:
代码如下: $("select#sel option[value='3']").remove();
10.删除第几个option:
代码如下: $(" select#sel option ").eq(索引值).remove();索引值=0,1,2.... 如删除第3个Radio: $(" select#sel option ").eq(2).remove();
11.删除第一个option:
代码如下: $(" select#sel option ").eq(0).remove(); 或者 $("select#sel option:first").remove();
12. 删除最后一个option:
代码如下: $("select#sel option:last").remove();
13. 删除dropdownlist:
代码如下: $("select#sel").remove();
14.在select后面添加一个option:
代码如下: $("select#sel").append("f");
15. 在select前面添加一个option:
代码如下: $("select#sel").prepend("0");
16. 遍历option:
代码如下: $(' select#sel option ').each(function (index, domEle) { //写入代码 });
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具18:33 by 慧可, ... 阅读,
1.html代码如下:
&form name="form1" id="form1"&
Select your favorite fruit:
&select id="mySelect" name="mySelect"&
&option value="11"&Apple&/option&
&option value="22" &Orange&/option&
&option value="33"&Pineapple&/option&
&option value="44"&Banana&/option&
&br /&&br /&
&input type="button" onclick="getIndex()"
value="Alert index of selected option"&
 2.javascript代码如下:
&script type="text/javascript"&
function getIndex()
  //从document对象中,获取select标签
  var a=document.getElementById("mySelect");
  //select标签获取的值其实是一个数组--a.options[]; 然后,选定项的下标是--a.selectedIndex
var b=a.options[a.selectedIndex].   今天又一次用到js了,我对这门语言实在是陌生,基本上很多都是要上网搜索才晓得什么用的。
现在在这里记录一点东西,呵呵,备忘用.........
页面源文件:
Html&asp&!--控件--&&asp:DropDownList&ID="drpl_ZYNJ"&runat="server"&Width="78px"&&&&&&&&&&&&&&&&&&&&&&asp:ListItem&&0&/asp:ListItem&&&&&&&&&&&&&&&&&&&&&&asp:ListItem&5&/asp:ListItem&&&&&&&&&&&&&&&&&&&&&&asp:ListItem&Selected="True"&10&/asp:ListItem&&&&&&&&&&&&&&&&&&&&&&asp:ListItem&15&/asp:ListItem&&&&&&&&&&&&&&&&&&&&&&asp:ListItem&20&/asp:ListItem&&&&&&&&&&&&&&&&&&/asp:DropDownList&&div&&id=layerclass&&style="visibility:"&&&&&&&&&&&label&style="font-weight:color:&#3366"&测试范围&/label&&&&&&&&&&&asp:TextBox&ID="tbx_classview"&&Width="352px"&runat="server"&ReadOnly="True"&TextMode="MultiLine"&Height="65px"&&&/asp:TextBox&&/div&&!--触发按钮--&&a&href="#"&&img&ID="imgbt_addclass"&src="Image/btn_addClass.gif"&name="imgbt_addclass"&style="border-width:0&vertical-align:"&onclick="ShowLayer()"&/&&/a&&br&/&
JavaScript:
Codefunction&ShowLayer()&{&&&&layerclass.style.visibility="visible";&&&&var&tbxclass&=&window.document.getElementById("tbx_classview");&&&&var&drplZYNJ&=&window.document.getElementById("drpl_ZYNJ");&&&&//&选择项的索引&&&&var&index&&&=&&&drplZYNJ.selectedI&&&&&&//选择项的值&&&&var&Value&&&=&&&drplZYNJ.options[index].&&&&&&&//选择项的内容&&&&var&Texts&&&&&=&&&drplZYNJ.options[index].&&&//下拉框选项个数&&&&window.alert(drplZYNJ.options.length);}
阅读(...) 评论()}

我要回帖

更多关于 select value 选中 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信