这是我的jquery代码,对输入有效,但对textarea没有任何想法?检查textarea是否为空
$(".masterform input,textarea").each(function() {
if ($(this).val() == "") {
verif = false;
}
});
这是我的jquery代码,对输入有效,但对textarea没有任何想法?检查textarea是否为空
$(".masterform input,textarea").each(function() {
if ($(this).val() == "") {
verif = false;
}
});
也许你有这样的 “文本域” 标签的内部空间:
<textarea> </textarea>
把标签越近,就像这样:
<textarea></textarea>
可以肯定,我会建议也使用trim()
方法。下面是关于如何使用trim()
链接:。
我宁愿建议使用'.trim()' – Rajesh
你必须使用$修剪你的IF因为textarea的默认配备了空白。
使用
if(!$.trim($("#textarea").val())){
// textarea is empty
}
在你的代码SAMPE应该是这样的:
$(".masterform input,textarea").each(function() {
if(!$.trim($(this).val()) == ""){
verif = false;
}
});
问候
塞萨尔·奥利维拉
粘贴HTML –
应该work..paste你的html – Sameer
有可能会有一些流浪的空白(使用'tri米'),或自定义的占位符? – mane