Jquery弹出框 [英] Jquery Popup Box
问题描述
我是JavaScript和Jquery的新手。我googled Jquery弹出的例子在线。我想要的消息说我们的网站还没有完成,但随时浏览我们有什么。我会包括我发现的代码示例,但它看起来真的很奇怪。我不知道函数的名称和如何执行它使用window.onload = function();码。我还想要一个按钮关闭,关闭文本框。这里应该是什么样子: http:// demo .tutorialzine.com / 2010/12 / better-confirm-box-jquery-css3 /
I'm new to JavaScript and Jquery. I googled Jquery pop-up examples online. I want the message to say "Our website is not yet complete, but feel free to browse what we have." I'll include the code example I found, but it looks really weird. I'm not sure what the name of the function is and how to execute it using the window.onload = function(); code. I also want to have a button 'close' that closes the text box. Here'a what it should look like: 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);
编辑:我收到加载时显示的消息。我将第二部分中的代码更改为
I got the message to show up on loading. I changed the code in the second part to
$('。item .delete')ready >
$('.item .delete').ready(function(){
推荐答案
将此页放置。
确保您的问题的第一部分
也包括在内。
Make sure that the first part
of your question is also included.
它会在
此外,您可以更改标题,我只是添加了一个占位符。
Also you can change the Heading, I just added a placeholder.
$(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.
}
{
});
});
这篇关于Jquery弹出框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!