【问题标题】:how to remove onclick from <form> and <button>如何从 <form> 和 <button> 中删除 onclick
【发布时间】:2017-11-03 06:10:06
【问题描述】:

您好,我对以下代码有疑问:

<form id="signon_form"  method="post" action="r1.php" class="form-signin" name="">
  <div id="error" class="error">
    <img src="images/error_button.png" /> <span id="error_message"></span>
  </div>

  <div class="input_info_container">
    <div class="input_text">
      <label id="username_input_label" class="user_label" for=
      "username_input" style=""></label> <input id="username_input" name=
      "username" type="text" class="input_fields username_input" autocorrect=
      "off" autocapitalize="off" autocomplete="off" tabindex="1" placeholder="example@email.ca"/>
    </div>

    <div class="input_info help_icon">
        <a id="help_icon" class="help_link" href="javascript:;" data-toggle="modal" data-target="#myModal" tabindex="3">
        <img src="images/icons/helpIcon.png"><br/>
        Help
        </a>
    </div>
  </div>

  <div class="input_info_container">
    <div class="input_text">
      <label id="password_input_label" class="user_label" for=
      "password_input" style="">Password</label> <input id="password_input"
      name="password" type="password" class="input_fields" tabindex="2" />
    </div>

    <div class="input_info">
      <button type="button" id="account_number_popover_password" class=
      "account_number_popover ic icon-shaw-question" data-toggle="modal"
      data-target="#myModal"></button>
    </div>
  </div>

  <div class="clearfix"></div>

  <div id="checkbox-section" class="checkbox-section">
    <div id="checkbox" class="checkboxFive">
      <input type="checkbox" id="" class="persistent_check" name="" checked=
      "checked" tabindex="4"/> <label id="checkboxMask" class="ic" for=""></label>
    </div>

    <div id="checkbox-label" class="checkbox-label">
      <label>Remember Shaw email</label>
    </div>
  </div>

  <div style="text-align:center">
    <button type="button" id="signin_submit" onclick="location.href='r1.php'" class=
    "button button_disabled"  tabindex="5">Sign in</button>
  </div>

  <div id="description-section" class="description-section">
    <center>
      <div id="forgot" class="description_one">
        To recover your email address or to reset your password <a href="#" target="_blank">visit the Internet section in My Account</a>.
      </div>

      <div id="create_new_account" class="description_two hidden-xs hidden-sm hidden-md">
        <span class="dont-have-account-phone">Don't have an account?</span>
        <a target="_self" data-event="navigation-element" data-value=
        "signon|body|create-one-now-link" id="create_one_now" href=
        "#"><span class=
        "dont-have-account-desktop">Don't have an account?</span>
        <span class="create-one-now-url">Create one now.</span></a>
      </div>
    </center>
  </div><input type="hidden" id="anchor" name="anchor" value="" />
</form>

你看到我有一个r1.php 形式的操作,并且按钮有一个onclick="location.href='r1.php'" 如果我删除它登录按钮不起作用我想摆脱它你能帮帮我吗伙计们我是一个初学者,正在尝试使用网站的源代码来学习一点,如果你能帮助我,我会非常棒的

【问题讨论】:

  • 一个表单需要一个action;它告诉表单将​​数据发送到哪里。如果您尝试将其发送到您当前所在的页面,只需使用action='#'
  • 我给了它 action="r1.php" 因为我希望它转到页面 r1.php

标签: javascript forms button onclick action


【解决方案1】:

您要查找的是实际表单提交,而不是简单的重定向。

代替:

<button type="button" id="signin_submit" onclick="location.href='r1.php'" class="button button_disabled" tabindex="5">Sign in</button>

您需要input 类型的submit

<input type="submit" value="Submit" id="signin_submit">

这告诉按钮实际POST数据。请注意,您可能需要稍微调整 CSS 以提供所需的显示。

希望这会有所帮助!

【讨论】:

  • 是的,谢谢,这真的很有帮助,我现在就去测试
  • 可以将现有按钮更改为提交类型(或省略类型属性,因为按钮默认为提交)。
  • 很高兴听到此解决方案似乎对您有用。一旦您确认此解决方案解决了您的问题,请不要忘记通过单击投票按钮下方的灰色复选标记来将解决方案标记为正确 - 这会将其从“未回答的问题”队列中删除,并为双方授予声誉提问者和回答者。当然,这么说,您没有义务将我的答案(或任何其他答案)标记为正确,尽管这确实有助于保持事情顺利进行:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-26
  • 1970-01-01
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多