[英]create clickable button and pop-up
我有“创建用户”表格,需要帮助。 在我要用户单击的链接之一上,然后将弹出带有信息的小弹出窗口,然后他们关闭弹出窗口并继续填写表格。 以下是代码:
<div class="users form">
<?php
echo $this->Form->create('User', array (
'type' => 'post',
'inputDefaults' => array (
'div' => false
)
)
);
?>
<script>
$(document).ready(function() {
$('#UserFirstName').focus();
});
</script>
<fieldset>
<legend></legend>
<h2>Registration</h2>
<?php
echo $this->Form->input('firstName');
echo '<div class=\'clear\'></div>';
echo $this->Form->input('lastName');
echo '<div class=\'clear\'></div>';
echo $this->Form->input('username');
echo '<div class=\'clear\'></div>';
echo $this->Form->input('password', array ('class' => 'short'));
echo '<div class=\'clear\'></div>';
echo $this->Form->input('password_confirm', array('type' => 'password', 'label' => 'Confirm Password: ', 'class' => 'short'));
echo '<div class=\'clear\'></div>';
echo $this->Form->input('email', array('label' => 'Email: ', 'default' => $email));
echo '<div class=\'clear\'></div>';
echo $this->Form->input('id', array('label' => 'id: ', 'type' => 'hidden', 'default' => 37));
$qmark = $this->Html->image('qmark.png', array('height' => 15));
echo '<div class=\'clear\'></div>';
echo $this->Form->input('number', array('label' => 'Number:', 'class' => 'short', 'after' => $qmark));
echo '<div class=\'clear\'></div>';
?>
我希望用户单击qmark按钮,然后会弹出一个小窗口,其中包含该字段的定义。
echo $this->Form->input('number', array('label' => 'Number:', 'class' => 'short', 'after' => $qmark));
先谢谢您的帮助。
这个给你!
$(document).ready(function() {
$('input[name="number"]').click(function() {
alert('Display your popup here...'); // maybe you should use another js library for popup
});
});
再见!
实际上,您必须使用以下命令在按钮上添加click事件的侦听器:
$('input[name="number"]').click(function() {
// Your code here
}
您可以使用著名的JQuery-UI对话框: http : //jqueryui.com/demos/dialog/它非常易于使用。
您可以在主页中创建框的内容(在显示为div的div中),或者以前使用ajax调用检索内容,然后打开包含内容的对话框。
您必须在用户单击按钮时将其绑定(添加一个侦听器)到该按钮,以便它可以显示您的弹出窗口,不要忘记将ID添加到您希望使其可单击的按钮或元素,我建议使用此标记:
<a href="#"></a>
$("#button").click(function(e){
e.preventDefault();
$("#popup").show();
});
如果使用标记,则必须添加preventDefault(),以防止浏览器更改光标的焦点。
另外,您还必须使用CSS创建“弹出式窗口”,以使其悬浮在网站的其他元素上,因为默认情况下可能会阻止另一个浏览器窗口,并且我认为这是一种不好的可用性做法。
不要忘记隐藏弹出框,可以使用具有以下属性的CSS来做到这一点:
visible:none;
在这里,我已经完成了上述问题的完整解决方案。
演示 http://codebins.com/bin/4ldqp6y
的HTML
<input type="button" id="btnSignUp" value="SignUp" />
<div id="popup">
<div id="popupinfo">
<p> Now, your registration form has been loaded...! </p>
<p> You have field your required fields and submit form.</p>
<p class="button"><a href="javascript:void(0);">OK</a></p>
</div>
</div>
<div id="registerDiv">
<p class="required">Fields with Mark (*) are required fields </p>
<form name="frmregister" id="frmregister" method="post" action="#registerDiv">
<table cellpadding="0" cellspacing="0" class="table" border="0">
<tr>
<td>*Name:</td>
<td><input type="text" class="input" size="17" /></td>
</tr>
<tr>
<td>*Username:</td>
<td><input type="text" class="input" size="17" /></td>
</tr>
<tr>
<td>*Password:</td>
<td><input type="password" class="input" size="17" /></td>
</tr>
<tr>
<td>*Confirm Password:</td>
<td><input type="password" class="input" size="17" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" class="input" size="17" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Register" id="btnsubmit" /></td>
</tr>
</table>
</form>
</div>
的CSS
.input{
border:1px solid #333;
}
.required{
color:red;
font-size:12px;
}
#registerDiv{
display:none;
margin-top:10px;
margin-left:20px;
border:2px solid #333;
padding:3px;
background:#cdcdcd;
width:280px;
text-align:center;
}
#popup{
display:none;
padding:10px;
background:#969696;
position:absolute;
top:25%;
left:25%;
z-index: 99999;
opacity:100%;
}
#popupinfo{
padding:2px;
text-align:center;
background:#cfcfcf;
}
#popupinfo p{
font-size:14px;
}
#popupinfo .button {
text-align:center;
}
#popupinfo .button a{
text-decoration:none;
border:1px solid #333;
width:20px;
padding:5px;
background:#1A1A1A;
color:#eee;
}
#popupinfo .button a:hover{
background:#eee;
color:#1a1a1a;
}
#mask{
background: #000;
position: fixed;
left: 0;
top: 0;
z-index: 10;
width: 100%;
height: 100%;
opacity: 0.8;
z-index: 999;
}
jQuery的
$(function() {
$("#btnSignUp").click(function() {
$("#registerDiv").fadeIn(300);
$("body").append("<div id='mask'></div>");
$("#mask").fadeIn(300);
$("#popup").fadeIn(300);
});
$("#popup .button a").click(function() {
$("#popup").fadeOut(300, function() {
$("#mask").remove();
});
$("#frmregister").find("input:first").focus();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.