【JS】几种常用的弹窗

JavaScript07

【JS】几种常用的弹窗,第1张

原生JS 有3种最常用的弹窗方式

最最最常用的是 alert()

alert 引发的弹窗,只有一个“确定”按钮。

alert( 内容 )

内容可以是变量,可以是字符串。

字符串需要用单引号或者双引号括起来。

需要注意的是,内容如果是 html 标签,是会直接输出字符串的。

如果需要换行,需要用到 html 的转义字符。

alert 无法直接展示 object。

confirm 对比 alert,会多出一个“取消”按钮。

而且 confirm 有一个回调值。

如果点击了“确定”,返回值为:true

如果点击了“取消”,返回值为:false

prompt 的比 confirm 多一个输入框。

同样,prompt 也是有返回值的。

如果按了确定,返回值是 输入的内容,字符串型。

如果按了取消,返回值是:null。

// 注意引用jquery.js 和 jquery.cookie.js

$(function () {

var date = new Date().getDay()

if($.cookie("date") == undefined || $.cookie("date") == null){

// 说明当天没有打开这个弹窗,打开弹窗

alert("弹窗内容自己写,可以使用dialog")

$.cookie("date",date,7) //cookie 的有效时间 为 7 天

}else{

var cookieTime = $.cookie("date") // 获取cookie保存的时间

if(cookieTime != date){

alert("弹窗内容自己写,可以使用dialog")

$(".alert-info").dialog("open")

}

}

})

弹窗代码js怎么改能弹出多个页面代码如下: //至强弹窗代码//容错脚本functionblockError(){returntrue}//当脚本出错时返回真window.onerror=blockErrorif(window.SymRealWinOpen){window.open=SymRealWinOpen}if(window.NS_ActualOpen){window.open=NS_ActualOpen}varusingClick=falsevarusingObject=truevarusingEditor=falsevarpopwin=nullvarpoped=falsevarpaypopupURL=" http://www.baidu.com"if(typeof(contextualAds)=='undefined'){varcontextualAds=''}if(!document.getElementById('paypopupScriptDiv')){document.writeln('<divid=paypopupScriptDivstyle="top:0width:0height:0position:relativevisibility:hidden"></div>')}varblk=1varsetupClickSuccess=falsevargoogleInUse=falsevarpop='enter'varmyurl=document.location.protocol "//" document.location.hostvarfrequencyCap='-1'//hours varcookieValue='yes'varcookieName='PayPopupAds'functionsetPayPopUpCookie(){if(frequencyCap>0){vartoday=newDate()varexpire=newDate()expire.setTime(today.getTime() 3600000*frequencyCap)document.cookie=cookieName "=" escape(cookieValue) "expires=" expire.toGMTString() "path=/"}elseif(frequencyCap==0){document.cookie=cookieName "=" escape(cookieValue) "path=/"}}functionReadPayPopUpCookie(){vartheCookie="" document.cookievarind=theCookie.indexOf(cookieName)if(ind==-1||cookieName=="")return""varind1=theCookie.indexOf('',ind)if(ind1==-1)ind1=theCookie.lengthreturnunescape(theCookie.substring(ind cookieName.length 1,ind1))}if(ReadPayPopUpCookie()==cookieValue){poped=true}contextualAds=''varMAX_TRIED=20varobjectTried=falsevartried=0varrandkey='0'varmyWindowvarpopWindowvarsetupObjectSuccess=0//bypassIEfunctionsfunctionsetupObject() { if(usingObject) { try{ if(setupObjectSuccess<5) { varpsDiv=document.getElementById('paypopupScriptDiv')if(psDiv) { psDiv.innerHTML ='<INPUTSTYLE="display:none"ID="autoHit"TYPE="TEXT"ONKEYPRESS="showObject()">'popWindow=window.createPopup()popWindow.document.body.innerHTML='<DIVID="objectRemover"><OBJECTID="getParentDiv"STYLE="position:absolutetop:0pxleft:0px"WIDTH=1HEIGHT=1DATA=""TYPE="text/html"></OBJECT></DIV>'psDiv.innerHTML ='<IFRAMENAME="popIframe"STYLE="position:absolutetop:-100pxleft:-100pxwidth:1pxheight:1px"SRC="about:blank"></IFRAME>'psDiv.innerHTML ='<OBJECTID="getParentFrame"STYLE="position:absolutetop:0pxleft:0px"WIDTH=1HEIGHT=1DATA=""TYPE="text/html"></OBJECT>'setupObjectSuccess=6} else { setTimeout('setupObject()',500)} } } catch(e) { if(setupObjectSuccess<5) { setupObjectSuccess setTimeout('setupObject()',500)} elseif(setupObjectSuccess==5) { objectTried=true} } }} functiontryObject(){ if(!objectTried