我正在使用JQuery验证HTML表单,但是“扩展名”规则不起作用(即使我已经包含了additional-methods.js
文件。我也测试了其他“规则”(这也是来自该js文件),并且这些文件似乎正常运行,所以我不确定为什么扩展名不是这样。
这是html / JS代码:
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
<form method="POST" id="regForm" action="{{ url_for('pipeline') }}">
<div class="tab">
<h3>User Assets:</h3>
<br>
<label>Interval BED File</label>
{{ form.target(placeholder="(e.g. Exome-NGv3.bed)...", oninput="this.className = ''") }}
<div class="form-group required">
<label>Sentieon Package Name</label>
{{ form.sentieon_package_name(placeholder="(e.g. sentieon-genomics-201711.01.tar.gz)...", oninput="this.className = ''") }}
</div>
<div class="form-group required">
<label>Sentieon License Name</label>
{{ form.sentieon_license_name(placeholder="(e.g mylicense.lic)...", oninput="this.className = ''") }}
</div>
</div>
</form>
<script>
$(document).ready(function () {
$('#regForm').validate({ // initialize the plugin
rules: {
sentieon_package_name: {
required: true,
extension: "tar|tar.gz"
},
sentieon_license_name: {
required: true,
extension: "lic"
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
});
</script>
答案 0 :(得分:0)
我可以看到在代码的第2行中,您有一个打开的<script>
标签。这就是造成您的问题的原因。更改此:
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
<script>
对此:
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
您的所有问题都将得到解决。