關(guān)于函數(shù)之間的值的引用問題
? ??<script?type="text/javascript">?? ????function?openWindow(){ ????????var?message=confirm("are?u?sure?to?open?a?new?window?"); ????????if(message==true){ ????????????var?newWebsite=prompt("enter?a?new?website:","http://idcbgp.cn/"); ????????????if(newWebsite!=null){ ????????????window.open(newWebsite,'_blank','width=400px,height=500px,toolbar=no,menubar=no'); ????????????}else{document.write("over?again!");} ???????????? ????????}else{ ????????????document.write("nnothing?to?do!"); ????????} ????} ????function?closeWindow(){ ????????var?clOpen=confirm("are?u?sure?to?close?the?window?"); ????????if(clOpen==true){ ????????????newWebsite.close();//請問我該怎樣引用到另一個函數(shù)里面定義的newWensite呢?? ????????}else{ ????????????document.write("the?window?isn't?closed!"); ????????????openWindow(); ????????} ????} ???????? ????//?新窗口打開時彈出確認框,是否打開 ????//?通過輸入對話框,確定打開的網(wǎng)址,默認為?http://idcbgp.cn/ ????//打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。 ???? ???? ??</script>? ?</head>? ?<body>? ???<input?type="button"?value="新窗口打開網(wǎng)站"?onclick="openWindow()"?/> ????<input?type="button"?value="close?the?wb"?onclick="closeWindow()"?/>? ?</body> </html>
我這樣定義了兩個函數(shù),一個打開一個關(guān)閉,可是我關(guān)閉的函數(shù)里面該怎樣引用打開函數(shù)里面的值呢,還是需要重新定義?
2016-04-08
你中間的close書寫有錯誤,你可以改一下,然后改為window.close{newwebsite};試試,我也是初學(xué),大家互相交流!
2016-04-08
http://idcbgp.cn/? ?網(wǎng)址的 “:”換英文的":"
2016-04-08
? ? <script type="text/javascript">
? ??
? ? var newWebsite;//此時newWebsite 是全局變量;
? ? function openWindow() {
? ? ? ? var message = confirm("are u sure to open a new window?");
? ? ? ? if (message == true) {
? ? ? ? ? ? newWebsite = prompt("enter a new website:", "http://idcbgp.cn");
? ? ? ? ? ? if (newWebsite != null) {
? ? ? ? ? ? ? ? newWebsite = window.open(newWebsite, '_blank', 'width=400px,height=500px,toolbar=no,menubar=no');
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? document.write("over again!");
? ? ? ? ? ? }
? ? ? ? } else {
? ? ? ? ? ? document.write("nnothing to do!");
? ? ? ? }
? ? }
? ? function closeWindow() {
? ? ? ? var clOpen = confirm("are u sure to close the window?");
? ? ? ? if (clOpen == true) {
? ? ? ? ? ? newWebsite.close();//請問我該怎樣引用到另一個函數(shù)里面定義的newWensite呢??
? ? ? ? } else {
? ? ? ? ? ? document.write("the window isn't closed!");
? ? ? ? ? ? //openWindow();
? ? ? ? }
? ? }
? ? </script>
//親測有效,不過不知道這樣解釋對不對0.0
2016-04-08
你用window.open打開,就用window.close關(guān)閉就可以了