【问题标题】:How to change the href of a button?如何更改按钮的href?
【发布时间】:2014-12-21 07:41:02
【问题描述】:

我有这个:

<input type="submit" class="inputlogin submit" name="register" style="margin-top: 5px;" value="Maak mijn account en log in!">

然后它去注册/注册。我希望它转到 /me,我该怎么做?

【问题讨论】:

  • 将表单中的操作值更改为 /me(我假设您已经对表单进行了编码)
  • @KunjanThadani 我在哪里可以找到行动的价值?
  • 显示足够的代码来重现问题,并解释问题是什么。 “去注册”并没有真正说明会发生什么。至少,您需要包含一个 form 元素并解释提交时会发生什么。

标签: html button input href


【解决方案1】:

Musa,欢迎堆栈溢出!

提交按钮正如其名称所说:它提交一个表单。现在哪里提交表单不是提交按钮的属性,而是表单的属性。

您会发现,提交按钮是&lt;form action="..."&gt; .. &lt;/form&gt; 构造的一部分。通过更改表单的 action 属性,您可以将其指向另一个 URL,例如到“/我”

【讨论】:

    【解决方案2】:

    输入引用的页面是在&lt;form&gt; 的action 属性中定义的,而不是&lt;input&gt; 本身。

    <form action="/me" method="get">
    

    【讨论】:

      【解决方案3】:

      你的代码必须是这样的:

      <form action="/me" method="post">
          <input type="submit" class="inputlogin submit" name="register" style="margin-top: 5px;" value="Maak mijn account en log in!">
      </form>
      

      【讨论】:

        【解决方案4】:

        我现在真的很困惑。所以,我有&lt;input type="submit" class="inputlogin submit" name="register" style="margin-top: 5px;" value="Maak mijn account en log in!"&gt;,我需要改成:&lt;input action="/me" method="get" type="submit" class="inputlogin submit" name="register" style="margin-top: 5px;" value="Maak mijn account en log in!"&gt;可能我需要早点说,但它是一个注册表,所以需要检查是否所有内容都填写,并且需要进入数据库。

        【讨论】:

        • 没有。您正在混合表单和输入标签。请检查我写表格的答案。最好看看 html 的基础知识。
        • 这不是答案。要澄清您的问题,请编辑您的问题。
        【解决方案5】:

        所以,我现在看到我已经有了正确的代码,但它转到 /register/me.. 我真的很惭愧...

        【讨论】:

          【解决方案6】:

          另一种方法是:

          <input type="button" class="inputlogin submit" style="margin-top: 5px;" value="Maak mijn account en log in!" onclick="parent.location='/me'">
          

          这利用了 onclick 并且可以在没有表单的情况下工作。请记住,它不是POST 表单

          【讨论】:

            【解决方案7】:
            <div class="text" style="font-weight:bold;padding:10px;"><?php if(isset($template->form->error)) { echo '<div class="error-messages-holder"><ul><li><p class="error-message">'.$template->form->error.'</p></li></ul></div>'; } ?>
                    <form method="post" action="{url}/me" autocomplete="off">
                      <label for="index_rusername">Neem een unieke nickname:</label><br />
                      <input type="text" placeholder=" Jouw gebruikersnaam " class="inputlogin" name="reg_username"><br />
                      <label for="index_rpassword">Kies een sterk wachtwoord:</label><br />
                      <input type="password" placeholder=" Jouw wachtwoord " class="inputlogin" name="reg_password"><br />
                      <label for="index_rconpassword">Typ je wachtwoord over:</label><br />
                      <input type="password" placeholder=" Jouw wachtwoord " class="inputlogin"  name="reg_rep_password"><br />
                      <label for="index_remail">Jouw email adres:</label><br />
                      <input type="text" placeholder=" Jouw e-mail adres " class="inputlogin"  name="reg_email"><br />
                      <input type="submit" class="inputlogin submit" name="register" style="margin-top: 5px;" value="Maak mijn account en log in!">
                    </form>
               </div>
              </div>
            

            我现在有这个代码。但是如果我按下按钮,它不会在数据库中注册,所以所有配置的东西都不会出现在“用户”表中。

            【讨论】:

              猜你喜欢
              • 2017-05-10
              • 2022-06-13
              • 2013-05-23
              • 1970-01-01
              • 2016-07-05
              • 2020-02-05
              • 1970-01-01
              • 2019-02-09
              • 1970-01-01
              相关资源
              最近更新 更多