[英]Jquery Popup Box
我是JavaScript和Jquery的新手。 我在网上搜索了Jquery弹出式示例。 我想要的信息是“我们的网站还没有完整,但随时可以浏览我们的网站。” 我将包括我找到的代码示例,但它看起来很奇怪。 我不确定函数的名称是什么以及如何使用window.onload = function()执行它。 码。 我还想要一个关闭文本框的“关闭”按钮。 这就是它应该是什么样子: http ://demo.tutorialzine.com/2010/12/better-confirm-box-jquery-css3/
这是第一部分:
(function($){
$.confirm = function(params){
if($('#confirmOverlay').length){
// A confirm is already shown on the page:
return false;
}
var buttonHTML = '';
$.each(params.buttons,function(name,obj){
// Generating the markup for the buttons:
buttonHTML += '<a href="#" class="button '+obj['class']+'">'+name+'<span></span></a>';
if(!obj.action){
obj.action = function(){};
}
});
var markup = [
'<div id="confirmOverlay">',
'<div id="confirmBox">',
'<h1>',params.title,'</h1>',
'<p>',params.message,'</p>',
'<div id="confirmButtons">',
buttonHTML,
'</div></div></div>'
].join('');
$(markup).hide().appendTo('body').fadeIn();
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons,function(name,obj){
buttons.eq(i++).click(function(){
// Calling the action attribute when a
// click occurs, and hiding the confirm.
obj.action();
$.confirm.hide();
return false;
});
});
}
$.confirm.hide = function(){
$('#confirmOverlay').fadeOut(function(){
$(this).remove();
});
}
})(jQuery);
这是第二部分:
$(document).ready(function(){
$('.item .delete').click(function(){
var elem = $(this).closest('.item');
$.confirm({
'title' : 'Delete Confirmation',
'message' : 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?',
'buttons' : {
'Yes' : {
'class' : 'blue',
'action': function(){
elem.slideUp();
}
},
'No' : {
'class' : 'gray',
'action': function(){} // Nothing to do in this case. You can as well omit the action property.
}
}
});
});
});
$(markup).hide().appendTo('body').fadeIn();
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons,function(name,obj){
buttons.eq(i++).click(function(){
// Calling the action attribute when a
// click occurs, and hiding the confirm.
obj.action();
$.confirm.hide();
return false;
});
});
}
$.confirm.hide = function(){
$('#confirmOverlay').fadeOut(function(){
$(this).remove();
});
}
})(jQuery);
编辑:我收到消息,显示加载。 我将第二部分的代码更改为
$('。item .delete')。ready(function(){
对话窗口,请看这个图片:
请查看此示例: http : //www.ericmmartin.com/projects/simplemodal/
有各种类型的流行模型: http : //www.ericmmartin.com/projects/
编码样本: http : //www.ericmmartin.com/projects/simplemodal/#examples
把它放在页面上。
确保您的问题的first part
也包含在内。
它将在页面中心创建一个带有消息和关闭按钮的对话框。
你也可以改变标题,我刚添加一个占位符。
$(document).ready(function(){
$.confirm({
'title' : 'Heading Goes Here',
'message' : 'Our website is not yet complete, '
+ 'but feel free to browse what we have.',
'buttons' : {
'Close' : {
'class' : 'blue',
'action': function(){} // Nothing to do in this case.
}
{
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.