简体   繁体   English

使用Jquery从多行文本框中检索值时出错

[英]Error while retrieving value from multiline textbox using Jquery

I have a requirement where I have to validate for the empty text of a multiline textbox in aspx. 我有一个要求,我必须验证aspx中多行文本框的空文本。 I am using jquery for this purpose. 我为此目的使用jQuery。

My aspx page would look like this: 我的aspx页面如下所示:

<asp:TextBox runat="server" ID="txtClarification" ClientIDMode="Static" TextMode="MultiLine" Rows="8" Style="width: 780px;"></asp:TextBox>

and in my Jquery function: 并在我的Jquery函数中:

var textbox = ('#txtClarification').val();
if (textbox.length == 0) {
    //do something
}

But the statement which I retrieve the textbox value throws error: 但是我检索文本框值的语句将引发错误:

Microsoft JScript runtime error: Object doesn't support property or method 'val' Microsoft JScript运行时错误:对象不支持属性或方法“ val”

Is there any difference in retrieving the value from a Multiline textbox? 从多行文本框中检索值是否有区别?

Don't forget the $ : 不要忘记$

var textbox = $('#txtClarification').val();
//------------^
if (textbox.length == 0) {
    //do something
}

Also I'm not an ASP.NET expert, but you may need to specify ClientID for your selector to work. 另外,我不是ASP.NET专家,但是您可能需要指定ClientID才能使选择器正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM