[英]JQuery Registration Form onclick popup
I am trying to make a Javascript JQuery registration form pop-up on link click. 我试图在单击链接时弹出一个Javascript JQuery注册表单。
So I have this button: 所以我有这个按钮:
<a href="#" class="cta">REGISTER NOW</a>
And I`m trying to make it pop-up a small simple html registration form that I can store in a hidden registration DIV. 我正在尝试使其弹出一个小的简单html注册表格,我可以将其存储在隐藏的注册DIV中。 Example: 例:
<div name="reg" style="visibility:hidden;">reg form</div>
I just need the simple registration form (Only full name and email) to pop-up (centered and mobile responsive) when that button is linked. 当链接该按钮时,我只需要简单的注册表格(仅全名和电子邮件)即可弹出(居中且对移动设备敏感)。
Can I get any help in doing this? 我可以在此方面获得任何帮助吗? Thank you. 谢谢。 I have tried with jquery dialog and almost everything found on Google, but it doesn't seem to work. 我已经尝试过使用jquery对话框和在Google上发现的几乎所有内容,但是它似乎不起作用。 Thanks. 谢谢。
You should really be using a class or id on you register div instead, but you can show the form like this: 您实际上应该在注册div时使用类或id,但是可以显示如下形式:
$('.cta').click(function() {
$('div[name="reg"]').css('visibility', 'visible');
})
Once you give your div a proper class/id, you can replace div[name="reg"]
with .class
or #id
. 为div赋予适当的class / id后,就可以将div[name="reg"]
替换为.class
或#id
。 Additionally, jQuery has several built-in functions for hiding and showing elements. 此外,jQuery具有一些内置功能,用于隐藏和显示元素。 To use these, you'll want to change visibility:hidden;
要使用这些功能,您需要更改visibility:hidden;
with display:none;
display:none;
. 。 Then, in the code I presented above, replace .css(...)
with one of the following: 然后,在上面提供的代码中,将.css(...)
替换为以下之一:
.show()
is an immediate effect, and is the same as changing the display property to block
. .show()
是立竿见影的效果,与将display属性更改为block
。 To remove again, use .hide()
. 要再次删除,请使用.hide()
。 .fadeIn()
, as the name suggests, is more of a gradual fading effect. 顾名思义, .fadeIn()
更像是逐渐淡入淡出效果。 Opposite of .fadeOut()
. 与.fadeOut()
相反。 slideDown()
is similar to an "accordian" effect, where the element starts at 0 height and "grows". slideDown()
类似于“ accordian”效果,其中元素从0高度开始并“ grows”。 Opposite of .slideUp()
. 与.slideUp()
相反。 You can also use .toggle()
, .fadeToggle()
, or slideToggle()
, respectively to alternate between showing and hiding the elements. 您还可以分别使用.toggle()
.fadeToggle()
或slideToggle()
在显示和隐藏元素之间交替。
I've created this JSFiddle to demonstrate these effects. 我创建了这个JSFiddle来演示这些效果。
As suggested by Mihailo , you could use Bootstrap Modals to make it responsive (mobile, tablet and PC). 根据Mihailo的建议,您可以使用Bootstrap Modals使其具有响应能力(移动设备,平板电脑和PC)。
<a data-toggle="modal" data-target=".bs-example-modal-sm" role="button" class="">Launch demo modal</a>
<div class="modal fade bs-example-modal-sm" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Registration</h4>
</div>
<div class="modal-body">
<form name="reg-form">
<div class="form-group">
<label for="user-name" class="control-label">Full Name:</label>
<input type="text" class="form-control" id="user-name">
</div>
<div class="form-group">
<label for="email" class="control-label">Email Address:</label>
<input type="text" class="form-control" id="email">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Here is the thing, there is a modal template with header section, body section and footer section. 这是东西,这里有一个带有标题部分,主体部分和页脚部分的模态模板。
div class="modal fade bs-example-modal-sm" div class =“ modal fade bs-example-modal-sm”
If you remove fade , then the modal will not animate. 如果删除淡入淡出 ,则模态将不进行动画处理。
More information regarding bootstrap modals is here 有关引导程序模态的更多信息在这里
Also, Please find the corresponding JsFiddle below: https://jsfiddle.net/Manoj85/7egtc2ne/5/ 另外,请在下面找到相应的JsFiddle: https ://jsfiddle.net/Manoj85/7egtc2ne/5/
Hope this helps!! 希望这可以帮助!!
Assuming you have a div called register, which you need to add, it will be like this: 假设您有一个称为register的div,需要添加它,它将像这样:
<script>
$(".cta").click(function() {
$("#register").css("hidden", false)
})
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.