简体   繁体   English

获取文本区域验证

[英]get text area validated

f F

this is an external javascript , but he name and email works correctly but it skips over the message box and goes to info submitted even if the text area is empty. 这是一个外部javascript,但是他的名字和电子邮件可以正常工作,但是即使文本区域为空,它也会跳过消息框并转到已提交的信息。 I've tried multiple ways and I tried to different functions and calling both and it didn't work correctly i do want to keep the if statements because I honestly don't know another way that doesn't mess with my other code.. 我尝试了多种方法,尝试使用不同的函数并同时调用它们,但均无法正常工作,我想保留if语句,因为老实说我不知道​​另一种不会与我的其他代码混淆的方法。

You got a whitespace in your textarea after the opening tag (the underscore represents the whitespace) 在开始标记后的文本区域中有一个空格(下划线表示空格)

<textarea>_
</textarea>

You get a whitespace, because between the open and closing tag you define the text that is in the textarea by default. 您将获得一个空格,因为默认情况下,您在开始标记和结束标记之间定义了文本区域中的文本。

However, you should trim the textarea content to remove any whitespace characters anyway. 但是,您应该修剪 textarea内容以删除所有空白字符。 You should consider this for the other fields, with sting input, as well. 对于其他字段,也应该考虑使用sting输入。

JS code is correct, I think the problem is the definition of Textarea. JS代码是正确的,我认为问题是Textarea的定义。 I fixed it and it works properly. 我修复了它,并且可以正常工作。

<textarea cols="40" rows="6" name="message" id="message"></textarea>

See https://jsfiddle.net/gwqq0x3a/ for complete example. 有关完整的示例,请参见https://jsfiddle.net/gwqq0x3a/

Textarea elements are defined like so: Textarea元素的定义如下:

<textarea cols="40" rows="6" name="message" id="message"></textarea

No need for that input stuff, textarea is already an input, and has the name and ID declared like so, that input type = "text" shouldn't be there :) 不需要输入内容,textarea已经是输入,并且具有这样声明的名称和ID,因此不应在其中input type = "text" :)

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

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