验证Twitter Bootstrap模型中的表单 [英] Validating a form in Twitter Bootstrap Model

查看:54
本文介绍了验证Twitter Bootstrap模型中的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模态中有一个表单,其中包含一些必填字段,但是当我点击提交"时,只需重新加载表单,我就没有收到用于提交表单jQuery的任何验证消息,如下所示:

I have a form in a modal with some required fields, but when I hit submit the form just reloads and I don't get any message for validation that I am using for submitting the form jQuery, as below :

<script>
    $('#InfroTextSubmit').click(function(){
        $('#InfroText').submit();
    });
</script>

Twitter引导程序模式代码为:

The Twitter Bootstrap Modal Code is :

<!-- Modal1 -->
<div id="myModal1" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Edit Introduction</h3>
  </div>
  <div class="modal-body">
    <form id="InfroText" method="POST">
      <input type="hidden" name="InfroText" value="1"/>
      <table>
        <tr><td>Title</td><td><input type="text" name="title" style="width:300px" required="require"/></td></tr>
        <tr><td>Introudction</td><td><textarea name="contect" style="width:300px;height:200px"></textarea></td></tr>
      </table>
    </form>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary" id="InfroTextSubmit">Save changes</button>
  </div>
</div>
<script>
    $('#InfroTextSubmit').click(function(){
        $('#InfroText').submit();
    });
</script>

那么,如果表单出现问题,我该如何验证表单而不让模型关闭并重新加载?

So how can i Validate the Form and not let the model close and reload if something is wrong with the form ?

此致

推荐答案

如果添加了必需属性,则无需添加任何脚本来验证表单文本字段.

You don't have to add any script for validating form text fields if you added the required attribute.

尝试一下

<input type="text" name="title" style="width:300px" required="required"/>

<input type="text" name="title" style="width:300px" required/>

这篇关于验证Twitter Bootstrap模型中的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆