如何创建一个带有窗体的弹出窗口? [英] How to create a popup window with a form?
本文介绍了如何创建一个带有窗体的弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的登录表单在下面的代码段。我需要的是通过点击菜单中的登录链接在弹出式窗口中打开此表单。我通过互联网搜索,但没有找到相关的答案。我知道我应该使用JavaScript,但我不知道如何使正确的代码。
我应该使用纯JS还是jQuery?为什么?
谢谢。
Here's my login form in the code snippet below. What I need is to open this form in a popup window by clicking Login link in the menu. I searched thru the internet but didn't found the relevant answer. I know I should use JavaScript but I don't know how make the right code. And should I use plain JS or jQuery? Why? Thank You.
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代码
Hi now used to simple jquery code as like this
$(document).ready(function(){
$('.login__form').hide();
$('.click').on('click', function(){
$('.login__form').show();
});
$('.closePopUP').on('click', function(){
$('.login__form').hide();
})
});
body {
background: #a7a7a7;
}
.closePopUP{position: absolute;
right: 8px;
top: 7px;
cursor: pointer;
border: solid 2px red;
border-radius: 50%;
font-size: 14px;
font-family: arial;
padding: 2px 6px;}
.login__form {
width: 320px;
padding: 20px;
background: #fff;
border-radius: 5px;
border-top: 5px solid #ff4e50;
margin: 0 auto;position:relative;
}
.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);
}
.click{float:left;cursor:pointer;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<button class="click">login popup</button>
<form name="login" class="login__form">
<span class="closePopUP">X</span>
<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>
这篇关于如何创建一个带有窗体的弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文