[英]Getting the value of a dropdownlist asp.net using javascript?
I keep getting an error on this saying its undefined or its null. 我一直在说这是未定义或为空的错误。 How do I get the drop down lists value? 如何获得下拉列表值?
So far I have: 到目前为止,我有:
this._ddlName = $("[id$=ddlName]"), elm);
var split = this._ddlName.value.split('-')[0];
The top line of code is working since I'm using it elsewhere to do something else. 因为我在其他地方使用它来做其他事情,所以代码的第一行一直在起作用。 But the bottom one throws the error. 但是最底层的抛出错误。 Any suggestions? 有什么建议么?
Since you are using JQuery: 由于您正在使用JQuery:
To get the selected value 获取所选值
$("#id").val();
You are missing ()
您失踪了()
To get value 获得价值
$('#dropDownId').val();
To get the currently selected text: 获取当前选定的文本:
$('#dropDownId :selected').text();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.