简体   繁体   English

使用JavaScript获取下拉列表asp.net的价值?

[英]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.

相关问题 使用Javascript在asp.net 4.5中下拉列表选择的值 - Dropdownlist selected value in asp.net 4.5 using Javascript 使用javascript填充ASP.NET下拉列表 - populate ASP.NET dropdownlist using javascript ASP.NET DropDownList JavaScript / jQuery获取选定的值并填充项目 - ASP.NET DropDownList JavaScript/jQuery getting selected value and populating items 使Javascript代码在ASP.Net中的DropDownList上的选择更改时触发 - Getting Javascript code to fire on a selection change on a DropDownList in ASP.Net 如何使用JavaScript将值从父asp.net下拉列表传递到弹出框中的文本框 - How to pass value from parent asp.net dropdownlist to textbox in popup using javascript 如何获取DropDownList选定的值,并将其发送到ASP.NET MVC 4中的控制器并使用JavaScript? - How can I get a DropDownList selected value and send it to the controller in ASP.NET MVC 4 and using JavaScript? 如何使用Javascript从asp.net的下拉列表中获取选定的值? - How to get selected value from dropdownlist in asp.net using Javascript? 如何使用asp.net中的JavaScript阻止用户更改DropDownList值? - How to block User from changing DropDownList value using javascript in asp.net? 我如何在不使用javascript和asp.net选择dropdownlist值的情况下显示验证 - how can i show validation on without selecting dropdownlist value using javascript and asp.net asp.net使用javascript隐藏dropdownlist中的特定项目 - asp.net Hide Specific items in dropdownlist using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM