我想在下面的字段應用驗證PLease幫助。正常驗證,如檢查是否爲空,如果空顯示錯誤的字段。我怎樣才能做到這一點 ?我怎樣才能把驗證下面的字段
我的HTML代碼
表單名稱
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" data-keyboard="false" data-backdrop="static"> <div class="modal-dialog modal-sm" role="document"> <div class="modal-content" style="padding:20px;"> <form id="contact-form" method="post" action="" role="form"> <div class="form-group"> <label for="frmName">Form Name *</label> <input id="frmName" type="text" name="frmName" class="form-control input-lg" placeholder="Please enter your form name *" required="required" data-error="form name is required." ></input> <div class="help-block with-errors"></div> </div> <div class="form-group"> <label for="txtProductName" class="control-label">Select Product : </label> <select required="required" data-error="form name is required." style="width: 260px;height :35px; font-size: 15px;" class="form-control" id="op1"> <option selected="selected">Select</option> </select> <div class="help-block with-errors"></div> </div> <div class="form-group"> <label for="frmdesc">Form Description *</label> <input id="frmdesc" type="text" name="name" class="form-control" placeholder="Please enter your form Desc *" required="required" data-error="full name is required."></input> <div class="help-block with-errors"></div> </div> <div class="modal-footer"> <button type="button" class="js-save-form fb-button" onclick="checkValidation();" data-dismiss="modal">Proceed</button> </div> </form> </div> </div> </div>
0
A
回答
0
希望這將是有用的。
的jQuery:
function checkValidation()
{
$('.required-fields').each(function(i, obj) {
if($(this).val() == "")
{
$(this).addClass('.alertClass');
}
else
{
$(this).removeClass('.alertClass');
}
});
}
CSS:
.alertClass{border-color: indianred;}
0
嘗試它,並檢查它。
//Check your Jquery and jquery.validate.min.js
//add script
<script>
$(document).ready(function() {
$("#contact-form").validate();
});
function validon() {
$("#contact-form").valid()
//or if ($("#contact-form").valid()) {}else{}
}
</script>
//html
<form id="contact-form" method="post" action="" role="form">
<input type="text" id="txtTest" name="Test" required />
<input type="button" id="btnvalid" value="valid" onclick="validon();" />
</form>
+0
其不工作我試過 –
+0
我找到一個例子。 http://jsfiddle.net/zqqdV/ 見。 –
+0
什麼我正在尋找是我想驗證窗體內引導模態,只有在成功驗證引導模態應該關閉,如果任何領域是空的,它應該顯示錯誤。 –
相關問題
- 1. 我怎樣才能把我的字段集並排?
- 2. 我們怎樣才能把scrollview放在android的EditText字段中?
- 3. 我怎樣才能把GridView的行
- 4. 我怎樣才能把插在VAR
- 5. 我怎樣才能把它變成shellcode?
- 6. 我怎樣才能把「子類」一類
- 7. 我怎樣才能把我的按鈕前面
- 8. 我怎樣才能把新的項目下的滾動型
- 9. 我怎樣才能得到下面的數組中的數字
- 10. 我怎樣才能把小數點後面的數值
- 11. 我怎樣才能把這段代碼轉換,從SQL到LINQ
- 12. PHP - 我怎樣才能做我自己的人工驗證?
- 13. 我怎樣才能把變量,而不是文字數字?
- 14. 我怎樣才能把我的ImageButton的值,以C#功能
- 15. 我怎樣才能把404頁面只使用routes.js?
- 16. 我怎樣才能把文本下每個imagaview
- 17. 我怎樣才能把一個字符的行猛砸
- 18. 我怎樣才能
- 19. 我怎樣才能
- 20. 我怎樣才能
- 21. 我怎樣才能
- 22. 我怎樣才能讓下BackgroundWorker的
- 23. 我怎樣才能使身份驗證的請求使用AJAX
- 24. 我怎樣才能呈現驗證消息的HTML ASP.NET MVC?
- 25. 我怎樣才能提高驗證錯誤了的FileField
- 26. 我怎樣才能把一個字符串數組
- 27. 我怎樣才能把它分成兩個字符串?
- 28. 我怎樣才能把我的表單值的JavaScript數組中
- 29. 我怎樣才能下載使用C++
- 30. 我怎樣才能在下拉
你忘了把你的javascript代碼片段 – Sojtin
在上面的代碼中按鈕,我正在彈出。 –