当我使用 validate.js 添加表单验证时,其验证正常并显示验证消息。但输入 type="submit"值在操作页面结构中显示两次。
为了说明,我有两个 .cfm 文件,index.cfm 具有带有验证的简单形式,actionview.cfm 具有
在 HTML 和 jQuery 验证代码中,在 index.cfm 中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery validation plug-in - main demo</title>
<link rel="stylesheet" href="css/screen.css">
<script src="../lib/jquery.js"></script>
<script src="../dist/jquery.validate.js"></script>
<script>
$.validator.setDefaults({
submitHandler: function() {
form.submit();
}
});
$(document).ready(function() {
$("#commentForm").validate();
});
</script>
<style>
#commentForm {
width: 500px;
}
#commentForm label {
width: 250px;
}
#commentForm label.error, #commentForm input.submit {
margin-left: 253px;
}
</style>
</head>
<body>
<div id="main">
<h1 id="banner"><a href="https://jqueryvalidation.org/">jQuery Validation Plugin</a> Demo</h1>
<p>Default submitHandler is set to submitting the form</p>
<form class="cmxform" id="commentForm" method="post" action="actionView.cfm">
<fieldset>
<legend>Please provide your name, email address (won't be published) and a comment</legend>
<p>
<label for="cname">Name (required, at least 2 characters)</label>
<input id="cname" name="name" minlength="2" type="text" required>
</p>
<p>
<label for="cemail">E-Mail (required)</label>
<input id="cemail" type="email" name="email" required>
</p>
<p>
<label for="curl">URL (optional)</label>
<input id="curl" type="url" name="url">
</p>
<p>
<label for="ccomment">Your comment (required)</label>
<textarea id="ccomment" name="comment" required></textarea>
</p>
<p>
<input class="submit" type="submit" name="submit" value="Submit">
</p>
</fieldset>
</form>
</div>
</body>
</html>
在actionView.cfm中,
<cfdump var="#form#" />
这里我给出了表单和转储结构的屏幕截图:
样本表格,
转储的结构,
在转储的结构中,“提交”按钮值为“Submit,Submit”。但通常我已经提交了显示“提交”的表单。我不确定为什么会发生这种情况?
有什么我错过的吗?如果有人解释为什么它显示两次,我非常感激?
提前致谢!
最佳答案
这确实是评论,但太长了。我刚刚运行了没有 jqueryvalidate 的代码,我得到了这个:
建议
改变
<input class="submit" type="submit" name="submit" value="Submit">
至
<button class="submit" type="submit" name="submit" value="">Submit</button>
关于jquery - 为什么表单操作页中的结构键值显示两次,如 "Submit,Submit"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56172176/