我的按钮坏了

My button didnt work

本文关键字:坏了 按钮 我的      更新时间:2023-09-26

嗨,我创建了一个登录表单,但当我点击登录时,我无法将用户名和密码发送到数据库,代码为:

CCD_ 1。

我可以发送用户名并通过这个代码:

<input id="enterbutton" type="submit" value="Login">

现在这个按钮看起来很难看,因为我在css中添加了这个按钮的图片。有了这个第一个代码按钮,看起来正是我想要的样子。如何解决这个问题?我的表单外观:

<form name="forma2" action="login.php" method="post">
        <br>
        <input class="inputbox" type="text" name="username" maxlength="18" placeholder="username">
        <br>
        <br>
        <input class="inputbox" type="password" name="password" placeholder="password">
        <br>
      <input type="submit" value="Login">
      </form>

工作,但没有css。

如果您想使用:

<a id="enter" href="#"><div id = "enterbutton">enter</"div></a>

因为你已经应用了一个特定的css,所以只需执行.即可

$('#enter').on('click', function(){
  $('#form').submit();
});

只需记住在表单中添加一个id即可。

如果您想使用button作为div,您应该在JavaScript中声明.click()事件如何:

$('#enter').on('click', function(){
  $('#form[name="forma2"]').submit();
});

您可以使用锚点提交表单,但您将使用事件处理程序:

<form id='myForm' name="forma2" action="login.php" method="post">
    <br>
    <input class="inputbox" type="text" name="username" maxlength="18" placeholder="username">
    <br>
    <br>
    <input class="inputbox" type="password" name="password" placeholder="password">
    <br>
  <a id="enter" href="#" onclick='document.getElementById("myForm").submit()'><div id = "enterbutton">enter</div></a>
  </form>
        <form name="forma2" action="login.php" method="post" id="myForm">
        <br>
        <input class="inputbox" type="text" name="username" maxlength="18" placeholder="username">
        <br>
        <br>
        <input class="inputbox" type="password" name="password" placeholder="password">
        <br>
        <a href="javascript:void(0);" onclick="submitMe();">Submit</a>
    </form>


    <script>
        function submitMe() {
            document.getElementById("myForm").submit();
        }
    </script>

@Grimbode的回答很好。但我不喜欢添加更多的脚本,您可能也没有jQuery。我们只能用CSS处理它。你的<a>的问题是你没有为此添加任何处理程序,所以无论何时你点击这个<a>,它都不会做任何事情。<input type="submit">代表形式,它处理的正是我们想要的。但通常,input带有一些默认的CSS,我不喜欢它,你也不喜欢。

你可以在这里找到我的样品:https://jsfiddle.net/y7mvu9zn/