本文介紹了如何使用 jquery 驗證插件驗證名稱中帶有點的輸入字段?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用 這個 jquery 驗證插件
<s:textfield cssClass="form-control input-default" name="contest.title" id="title" placeholder="Enter Title"
/>
驗證對此不起作用,但如果我將名稱更改為 title
- 驗證有效.
Validation doesn't work for this, but if I change the name to title
- validation works.
我嘗試搜索,但找不到驗證名稱中帶有 .
的字段的方法.
I tried searching, but couldn't find a means to validate fields with a .
in their name.
請幫忙
更新
腳本
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#contestform").validate({
submitHandler: function(form) {
// return false; // block the default submit action
},
rules: {
title: {
required: true
},
link: {
required: true
},
startdt: {
required: true
},
enddt: {
required: true
},
descr: {
required: true
},
},
messages: {
title: "Please enter a title",
link: "Please enter the sponser redirection link",
startdt: "Please select start date",
enddt: "Please select end date",
descr: "Please enter description"
}
});
});
</script>
表格的一部分
<form action="" enctype="multipart/form-data" method="post" id="contestform">
<s:hidden name="option" value="option"/>
<s:hidden name="contest.idcontest"/>
<div class="form-group">
<label for="title">Title</label>
<s:textfield cssClass="form-control input-default" name="contest.title" id="title" placeholder="Enter Title"
/>
</div>
推薦答案
你需要把字段名放在qoutes中.來自 插件文檔
You need to put the field names in qoutes. From the plugin documentation
名稱復雜的字段(括號、點)
Fields with complex names (brackets, dots)
當你有一個像 user[name] 這樣的 name 屬性時,確保把引號中的名稱.一般準則中的更多詳細信息.
When you have a name attribute like user[name], make sure to put the name in quotes. More details in the General Guidelines.
鏈接參考中的示例:
$("#myform").validate({
rules: {
// no quoting necessary
name: "required",
// quoting necessary!
"user[email]": "email",
// dots need quoting, too!
"user.address.street": "required"
}
});
這篇關于如何使用 jquery 驗證插件驗證名稱中帶有點的輸入字段?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!