我想在下面的字段应用验证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
在上面的代码中按钮,我正在弹出。 –