我发现因为我正在处理的所有表单都有一个提交按钮,该按钮包含’name =“submit”’属性,当我点击应该触发表单提交的链接时,触发器提交就会中断.
有谁知道我怎么能绕过这个.
下面的JQuery代码是我使用的:
$('#login_form :submit').each( function() { var $this = $(this); var f = this.form; var link = $('<a class="swap_link" href="#">' + $this.val() + '</a>') link.click(function() { $(f).trigger('submit'); return false; } ) $this.after(link).css({position:'absolute',top:'-2000px'}); } )
感谢任何帮助.谢谢
你好.看看下面的链接:
http://www.mr-scraggy.com/test.html
在此页面上,您可以看到表单的实际效果.在提交按钮中没有名称=“提交”的顶部表单有效.包含name =“submit”的底部表单没有. (当我说工作时,表单没有连接到任何脚本,但你可以看到顶部表单中的提交链接确实’某事’).
另见表格html:
<form id="swaplink" name="login" action="/action/login.php" method="post" accept-charset="utf-8" class="clearfix"> <input type="hidden" name="redirecturl" id="redirecturl" value="{$redirecturl}" /> <h2>My Account Login</h2> <ul id="login_form"> <li> <label for="username">Username:</label> <input type="text" name="username" id="username" class="input-text" maxlength="32" /> </li> <li> <label for="password">Password:</label> <input type="password" name="password" id="password" class="input-text" maxlength="32" /> </li> <li> <input type="submit" name="submit" value="Login" /> </li> </ul> {$failed_message} </form>
解决方法
这是因为您已将提交按钮命名为“提交”.因为这已经是表单对象的属性,所以它与提交事件的绑定混淆了.
请参阅jQuery docs中的此注释:
Forms and their child elements should
not use input names or ids that
conflict with properties of a form,
such as submit,length,or method.
Name conflicts can cause confusing
failures.
将提交按钮的名称更改为其他任何内容(例如“form_submit”),它将起作用.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。