prompt彈窗選取消還是會(huì)新建空窗口
{ var a =confirm(" 是否打開窗口 "); ? ? var b; ? if(a) ? ? { ? ?b=prompt("請(qǐng)輸入打開的網(wǎng)址:", "http://idcbgp.cn/"); ? ?if(b) ? ? ?{ window.open(' http://idcbgp.cn/','_blank','width:400px,height:500px,menubar:no,toolbar:no'); ? ? ? } ? ? } ? }?
?當(dāng)輸入網(wǎng)址那個(gè)彈窗選擇取消,還是會(huì)彈出一個(gè)新建空白網(wǎng)頁。該怎么設(shè)置取消呢
2016-06-22
prompt:如果用戶單擊提示框的取消按鈕,則返回 null。如果用戶單擊確認(rèn)按鈕,則返回輸入字段當(dāng)前顯示的文本。
所以你的b其實(shí)是網(wǎng)址,如果點(diǎn)取消就是null,判斷b是否為null即可。代碼如下
? ? ? ? ? ? var b = prompt("請(qǐng)輸入網(wǎng)址:","http://idcbgp.cn/");
? ? ? ? ? ? if (b!=null && b!="") {
? ? ? ? ? ? ? window.open(b,'_blank','width=400,height=50,menubar=no,toolbar=no');
? ? ? ? ? ? }
2016-06-22
好亂