链接到代码演示:http://www.queness.com/post/77/simple-jquery-modal-window-tutorial
<HTML xmlns="http://www.w3.org/1999/xhtml"><head> <Meta content="text/HTML; charset=windows-1252" http-equiv=Content-Type><SCRIPT type=text/JavaScript src="jquery-latest.pack.Js"></SCRIPT><SCRIPT>$(document).ready(function() { //if the cookie hasLaunch is not set,then show the modal window if (!readcookie('hasLaunch')) { //launch it launchWindow('#dialog'); //then set the cookie,so next time the modal won't be displaying again. createcookie('hasLaunch',1,365); } //if close button is clicked $('.window #close').click(function () { $('#mask').hIDe(); $('.window').hIDe(); }); //if mask is clicked $('#mask').click(function () { $(this).hIDe(); $('.window').hIDe(); }); $(window).resize(function () { var Box = $('#Boxes .window'); //Get the screen height and wIDth var maskHeight = $(document).height(); var maskWIDth = $(window).wIDth(); //Set height and wIDth to mask to fill up the whole screen $('#mask').CSS({'wIDth':maskWIDth,'height':maskHeight}); //Get the window height and wIDth var winH = $(window).height(); var winW = $(window).wIDth(); //Set the popup window to center Box.CSS('top',winH/2 - Box.height()/2); Box.CSS('left',winW/2 - Box.wIDth()/2); }); });function createcookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/";}function readcookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charat(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null;}function launchWindow(ID) { //Get the screen height and wIDth var maskHeight = $(document).height(); var maskWIDth = $(window).wIDth(); //Set heigth and wIDth to mask to fill up the whole screen $('#mask').CSS({'wIDth':maskWIDth,'height':maskHeight}); //Transition effect $('#mask').fadeIn(1000); $('#mask').fadeto("slow",0.8); //Get the window height and wIDth var winH = $(window).height(); var winW = $(window).wIDth(); //Set the popup window to center $(ID).CSS('top',winH/2-$(ID).height()); $(ID).CSS('left',winW/2-$(ID).wIDth()/2); //Transition effect $(ID).fadeIn(2000); }</SCRIPT><STYLE>body { Font-FAMILY: verdana; Font-SIZE: 15px}A { color: #333; TEXT-decoration: none}A:hover { color: #ccc; TEXT-decoration: none}#mask { Z-INDEX: 9000; position: absolute; BACKGROUND-color: #000; disPLAY: none; top: 0px; left: 0px}#Boxes .window { Z-INDEX: 9999; position: fixed; padding-BottOM: 20px; padding-left: 20px; WIDTH: 640px; padding-RIGHT: 20px; disPLAY: none; HEIGHT: 385px; padding-top: 20px}#Boxes #dialog { padding-BottOM: 10px; BACKGROUND-color: #ffffff; padding-left: 10px; WIDTH: 640px; padding-RIGHT: 10px; HEIGHT: 385px; padding-top: 10px}.redBox { color: #F00; Font-weight: bold;}.bold { Font-weight: bold;}</STYLE><div ID=Boxes> <div ID=dialog class=window><span > pop up message <A href="#" > Ok </a> </div><div ID=mask></div></div></HTML>解决方法 会话cookie是没有过期时间的cookie,因此请更改:
createcookie('hasLaunch',365);
至:
createcookie('hasLaunch',1);总结
以上是内存溢出为你收集整理的创建基于会话的cookie,jquery全部内容,希望文章能够帮你解决创建基于会话的cookie,jquery所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)