php - 如何使不同形式的按钮彼此相邻?
问题描述
首先,我为此使用了物化。我正在制作两个按钮,一个用于登录,一个用于注册,两者都采用不同的形式,我这样做了,所以注册按钮将直接指向注册页面而不是由 required 属性阻止,问题是,因为两个按钮来自不同的形式,它们不会彼此相邻,我不知道为什么,我需要两个按钮彼此相邻(注册按钮在登录按钮旁边)
<!DOCTYPE html>
<html>
<head>
<title>Sanrio Merch</title>
<link rel="stylesheet" type="text/css" href="css/materialize.min.css">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<style type="text/css">
body{
background-image: url("assets/bg.gif");
background-size: 100% 120vh;
background-repeat: no-repeat;
}
.card{
background: rgba(0,0,0,.4);
width: 40%;
height: 75vh;
margin: 9% auto;
}
label,input{
color: white;
font-size: 1em;
}
input{
border-bottom: 1px solid white !important;
}
input:focus{
box-shadow: 0 1px 0 0 white !important;
}
</style>
</head>
<body>
<div class="container">
<div class="card">
<form action="login.php" method="post">
<div class="card-action white-text brown">
<h3>SIGN IN</h3>
</div>
<div class="card-content">
<div class="form-field">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="username" required="">
<br><br>
<label for="password">Password</label>
<input type="password" id="password" name="pass" placeholder="password" required="">
</div><br>
</div><br><br>
<div class="form-field center-align">
<button class="btn-large brown" name ='sigin'style="margin-right: 2%;" type="submit" name="submit">Sign In</button>
</div>
</form>
<form action="login.php" method="post">
<button class="btn-large brown" name="register">Sign Up</button>
</form>
</div>
</div>
</div>
</body>
</html>
解决方案
您可以创建 2 个不带 type="submit" 的按钮并添加一些 jQuery,如下所示:
$( "#button_sign_up" ).click(function() {
$( "#form_sign_up" ).submit();
});
$( "#button_sign_in" ).click(function() {
$( "#form_sign_in" ).submit();
});
这样,您可以标记您的按钮以根据表单 ID 执行提交。现在您的按钮可以位于页面上的任何位置。确保您已分配表单和按钮 ID
推荐阅读
- html - div 应取屏幕高度减去(页眉+页脚和其他 div 的高度)
- swift - 小导航标题显示几秒钟
- azure - 无法从逻辑应用中删除或移动第一步?
- bash - 进程替换到“源”在 Mac OS 上不起作用
- sql-server - 在sql server中计算停车时间
- c# - 调用 Close 后抛出 System.ObjectDisposedException
- google-apps-script - 我可以在 gmail 中添加一个按钮来运行 Google Apps 脚本吗?
- c++ - 将参数传递给数组的构造函数
- android - 在 Room 数据库实体上实现 Parcelable 是一种好习惯吗?
- intel - 如何获取函数 sgx_ecc256_create_key_pair() 在 sgx enclave 中生成的公钥?