下面的代码片段是我的登录表单。我需要的是通过单击菜单中的 Login 链接在弹出窗口中打开此表单。我通过互联网搜索但没有找到相关答案。我知道我应该使用 JavaScript,但我不知道如何编写正确的代码。 我应该使用纯 JS 还是 jQuery?为什么? 谢谢。
body {
background: #a7a7a7;
}
.login__form {
width: 320px;
padding: 20px;
background: #fff;
border-radius: 5px;
border-top: 5px solid #ff4e50;
margin: 0 auto;
}
.login__form fieldset{
border: 0;
}
.login__form h3 {
text-align: center;
color: #666;
font-size: 18px;
text-transform: uppercase;
margin-top: 0;
margin-bottom: 20px;
font-weight: bold;
padding: 0;
margin: 0;
margin-bottom: 12px;
}
.login__form input {
width: 100%;
height: 42px;
box-sizing: border-box;
border-radius: 5px;
border: 1px solid #ccc;
margin-bottom: 20px;
font-size: 14px;
font-family: Montserrat;
padding: 0 20px 0 50px;
outline: none;
}
.login__form input#username {
background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px top no-repeat;
background-size: 16px 80px;
}
.login__form input#username:focus {
background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px bottom no-repeat;
background-size: 16px 80px;
}
.login__form input#password {
background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px top no-repeat;
background-size: 16px 80px;
}
.login__form input#password:focus {
background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px bottom no-repeat;
background-size: 16px 80px;
}
.login__form input:active, .login__form input:focus {
border: 1px solid #ff4e50;
}
.login__form input#button {
width: 100%;
height: 40px;
background: #ff4e50;
box-sizing: border-box;
border-radius: 5px;
border: 1px solid #e15960;
color: #fff;
font-weight: bold;
text-transform: uppercase;
font-size: 14px;
font-family: Montserrat;
outline: none;
cursor: pointer;
margin: 0;
padding: 0;
}
.login__form input#button:hover {
opacity: 0.7;
filter: alpha(opacity=70);
}
<form name="login" class="login__form">
<h3>Login</h3>
<fieldset>
<input type="text" value="" placeholder="Username" id="username">
<input type="password" value="" placeholder="Password" id="password">
<input type="submit" value="Submit" id="button">
</fieldset>
</form>
最佳答案
您可以使用 jquery UI :
$(function() {
$("#dialog").dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$("#opener").click(function() {
$("#dialog").dialog("open");
});
});
body {
background: #a7a7a7;
}
.login__form {
/*width: 320px;*/
padding: 20px;
background: #fff;
border-radius: 5px;
border-top: 5px solid #ff4e50;
margin: 0 auto;
}
.login__form fieldset {
border: 0;
}
.login__form h3 {
text-align: center;
color: #666;
font-size: 18px;
text-transform: uppercase;
margin-top: 0;
margin-bottom: 20px;
font-weight: bold;
padding: 0;
margin: 0;
margin-bottom: 12px;
}
.login__form input {
width: 100%;
height: 42px;
box-sizing: border-box;
border-radius: 5px;
border: 1px solid #ccc;
margin-bottom: 20px;
font-size: 14px;
font-family: Montserrat;
padding: 0 20px 0 50px;
outline: none;
}
.login__form input#username {
background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px top no-repeat;
background-size: 16px 80px;
}
.login__form input#username:focus {
background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px bottom no-repeat;
background-size: 16px 80px;
}
.login__form input#password {
background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px top no-repeat;
background-size: 16px 80px;
}
.login__form input#password:focus {
background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px bottom no-repeat;
background-size: 16px 80px;
}
.login__form input:active,
.login__form input:focus {
border: 1px solid #ff4e50;
}
.login__form input#button {
width: 100%;
height: 40px;
background: #ff4e50;
box-sizing: border-box;
border-radius: 5px;
border: 1px solid #e15960;
color: #fff;
font-weight: bold;
text-transform: uppercase;
font-size: 14px;
font-family: Montserrat;
outline: none;
cursor: pointer;
margin: 0;
padding: 0;
}
.login__form input#button:hover {
opacity: 0.7;
filter: alpha(opacity=70);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div id="dialog">
<form name="login" class="login__form">
<h3>Login</h3>
<fieldset>
<input type="text" value="" placeholder="Username" id="username">
<input type="password" value="" placeholder="Password" id="password">
<input type="submit" value="Submit" id="button">
</fieldset>
</form>
</div>
<button id="opener">Log In</button>
当然,您可以修改此代码以满足您的需求。
关于javascript - 如何使用表单创建弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32862509/