為什么總是同時打開兩個網(wǎng)頁而點(diǎn)按鈕卻只能關(guān)閉一個,哪位大神能幫我看看?代碼如下:
var mywin=window.open("http://idcbgp.cn");
? ? ?function clk(){
? ? ? ? mywin.close();??
? ? ?}
? </script>
</head>
<body>
? ? <input name="button" type="button" onClick="clk()" value="點(diǎn)擊我,關(guān)閉網(wǎng)站" />
</body>
2018-07-14
稍微改動了一下
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
? <script type="text/javascript">
? ? ?var mywin=window.open("http://idcbgp.cn","_blank","width=600,height=400,top=100,left=0");
? ? ?function clk(x){
? ? ?x.close();
? ? ?}
? </script>
</head>
<body>
? ? ?<input name="button" type="button" onClick="clk(mywin)" value="點(diǎn)擊我,關(guān)閉網(wǎng)站" />
</body>
</html>
2018-07-11
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
? <script type="text/javascript">
???? function clk(){
?????? var mywin=window.open("http://idcbgp.cn");
??????? mywin.close();?
???? }
?????
?</script>
</head>
<body>
??? <input name="button" type="button" onClick="clk()" value="點(diǎn)擊我,關(guān)閉網(wǎng)站" />
</body>
</html>
2018-04-26
window.open()方法的作用就是新打開一個窗口,如果你想關(guān)閉當(dāng)前窗口直接用 onClick="window.close",如果是想兩個窗口同時關(guān)閉,需要在clk()函數(shù)中加一行window.close;