我有一个由 Nicedit 转换为富文本编辑器的表单。我还对表单应用了 Jquery 验证插件,除了 textarea 标签外,一切正常。 textarea 标签没有响应 jquery 验证插件。当我单击提交按钮而不在文本区域中输入文本时,表单将被提交。如果有人能帮助我,我会很高兴。 下面是我的代码:
<!DOCTYPE html>
<head>
<script src="nicEdit.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<style>
body
{
font-family:Gotham,'sans-serif';
}
</style>
</body>
</head>
<body>
<form id="ruebenform" novalidate="novalidate">
Firstname: <input name="firstname" id="firstname">
<textarea id="thetextarea" rows="5" cols="45"></textarea>
<button type="submit">Submit</button>
</form>
<script type="text/javascript">
new nicEditor({maxHeight : 50}).panelInstance('thetextarea');
</script>
//Jquery validation script
<script>
$("#ruebenform").validate({
rules:{
firstname: {
required: true,
minlength: 2
},
thetextarea: {
required: true,
minlength: 2
}
},
messages: {
firstname: {
required: "Please enter a title",
minlength: "At least 2 characters"
},
thetextarea: {
required: "Please enter a description",
minlength: "At least 2 characters"
}
},
submitHandler: function(form) { return false; }
});
</script>
</body>
</html>
最佳答案
您需要为文本区域添加一个 ID。然后用 jQuery 调用它,检查长度并应用 css 规则。
关于jquery - 验证 nicedit 表单文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24845232/