prompt與comfirm的問題
function?openwindow(){ ??????var?mychar=prompt("是否打開窗口"); ????//?新窗口打開時(shí)彈出確認(rèn)框,是否打開 ????if(mychar==true) ????{ ????//?通過輸入對話框,確定打開的網(wǎng)址,默認(rèn)為?http://idcbgp.cn/ ?????window.open('http://idcbgp.cn','height=400,width=500','menubar=no,toolbar=no'); ?????} ????//打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。 ????else ????{ ???????? ????} ????} ????openwindow(); ???????為什么我把prompt改成comfirm,和if(mychar!=null)改為if(mychar==true)后就不能執(zhí)行了,
2015-10-26
prompt函數(shù)的返回值是一個(gè)字符串,所以mychar是字符串類型,一個(gè)字符串當(dāng)然不等于true了,所以當(dāng)然不會執(zhí)行window.open了。。
還有一點(diǎn):comfirm返回的就是布爾值,直接使用 if( mychar ) 判斷就行了,為什么還要比較 mychar == true 呢?