简体   繁体   English

单击锚标记时如何验证表单中的数据

[英]How do I validate data in a form when an anchor tag is clicked

I'm using Twitter's Bootstrap. 我正在使用Twitter的Bootstrap。 After the user enters data in my form, they click a button to register. 用户在我的表单中输入数据后,他们单击按钮进行注册。 This loads a modal with a summary of the data they entered for them to confirm. 这会加载一个模态,其中包含他们输入的数据摘要以供确认。 I want to validate the data after they click register, but before the modal loads. 我想在他们单击注册后但在模态加载之前验证数据。 How do I do that? 我怎么做?

This is one of my form elements 这是我的表单元素之一

<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
  <input id="inputEmail" class = "span11" type="text" placeholder="Email" name = "inputEmail" maxlength="32">
</div>

This loads the modal 这加载了模态

<div class="control-group">
<div class="controls">
  <a href="#myModal" role="button" class="btn" id="registerBtn" data-toggle="modal">Register</a>
</div>

Thanks 谢谢

try this, call function which validate your data. 试试这个,调用函数来验证您的数据。 i mentioned how to call function rest you know how to put validation... 我提到了如何调用函数休息,你知道如何进行验证...

<script type="text/javascript">
function rest(){
alert('asdf');
}
</script>

<a href="javascript:rest()" role="button" class="btn" id="registerBtn" data-toggle="modal">Register</a>

You can take control of how the Modal appears by doing it in javascript. 您可以通过在javascript中进行操作来控制Modal的显示方式。 Remove the data-toggle="modal" attribute and instead hook your button to a function that will eventually do: 删除data-toggle =“ modal”属性,然后将您的按钮挂接到最终将要执行的功能:

$('#myModal').modal('show');

You may have to initialise it beforehand or not, depending on your bootstrap version. 您可能需要预先初始化或不初始化它,具体取决于您的引导程序版本。 That would look like: 看起来像:

$('#myModal').modal();

For moar infos: 摩尔信息:

http://twitter.github.io/bootstrap/javascript.html#modals http://twitter.github.io/bootstrap/javascript.html#modals

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM