【问题标题】:Anchor tag acts as a form submit button?锚标记充当表单提交按钮?
【发布时间】:2017-08-18 16:35:27
【问题描述】:

锚标签充当表单提交按钮?

<form method="get" action="<?php bloginfo('url'); ?>/">
<div class="field-search">
    <input type="text" class="form-control input-lg" placeholder="Search for..." value="<?php the_search_query(); ?>">
    <a href="#" class="btn-search"><i class="fa fa-search font-16"></i></a>
</div>

【问题讨论】:

标签: button anchor


【解决方案1】:
<form action="test.aspx" type="POST">
    <label>
        <span>Username</span>
        <input type="text" name="UserName" id="UserName" class="input-text required" />
    </label>
    <label>
        <span>Password</span>
        <input type="password" name="Password" id="Password" class="input-text required" />
    </label>
    <label>
        <input type="checkbox" name="RememberMe" id="RememberMe" class="check-box" />
        <span class="checkboxlabel">Remember Me</span>
    </label>
    <div class="spacer">
        <a href="javascript:void(0)" class="login-button">Login</a>
    </div>
</form>

jquery

$(document).ready(function(){
   $(document).on("click",".login-button",function(){
     var form = $(this).closest("form");
     //console.log(form);
     form.submit();
   });
});

可能重复 (Anchor tag as submit button?)

(这是复制的答案)

【讨论】:

    【解决方案2】:

    试试这个方法看看是否有效。

    如下向你的锚标签添加一个点击事件并执行 event.stopPropagation()

    $('a').on('click', function(e){
         e.stopPropagation();
    })`
    

    看看这是否有效

    【讨论】:

      猜你喜欢
      • 2013-06-10
      • 2016-06-10
      • 2014-03-23
      • 2015-10-15
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 2021-09-04
      相关资源
      最近更新 更多