為啥我點(diǎn)擊按鈕沒有任何效果
<!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");
? ? function close(){
? ? ? ? var answer=confirm("是否要關(guān)閉此窗口?");
? ? ? ? if(answer==true){
? ? ? ? ? ? ?mywin.close();
? ? ? ? ? ? ?alert("已關(guān)閉");
? ? ? ? }else
? ? ? ? {
? ? ? ? ? ? alert("關(guān)閉失敗");
? ? ? ? }
? ? }
? </script>
</head>
<body>
? ? <input type="submit" value="點(diǎn)擊關(guān)閉" onclick="close()"/>
</body>
</html>
2024-08-14
<!DOCTYPE HTML>
<html>
<head>
? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
? ? <title>close()</title>
? ? <script type="text/javascript">
? ? ? ? function ?Wopen() {
? ? ? ? ? ? var answer = confirm("是否要打開此窗口?");
? ? ? ? ? ? var main = window.open('http://idcbgp.cn','_blank');
? ? ? ? ? ? if (answer == true) {
? ? ? ? ? ? ? ? main.close();
? ? ? ? ? ? ? ? window.close();
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? alert("打開失敗");
? ? ? ? ? ? }
? ? ? ? ? ?
? ? ? ? }
? ? </script>
</head>
<body>
? ? <input name="button" type="button" onClick=" Wopen()" value="點(diǎn)擊我,打開新窗口!" />
</body>
</html>
這樣就好了
2022-05-05
我也是個(gè)web初學(xué)者,但是有編程經(jīng)驗(yàn),我覺得應(yīng)該是close是一個(gè)內(nèi)置的方法
<!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");
? ? function closeWindow(){
? ? ? ? var answer=confirm("是否要關(guān)閉此窗口?");
? ? ? ? if(answer==true){
? ? ? ? ? ? ?mywin.close();
? ? ? ? ? ? ?alert("已關(guān)閉");
? ? ? ? }else
? ? ? ? {
? ? ? ? ? ? alert("關(guān)閉失敗");
? ? ? ? }
? ? }
? </script>
</head>
<body>
? ? <input type="submit" value="點(diǎn)擊關(guān)閉" onclick="closeWindow()"/>
</body>
</html>
上面這樣是可以的,把close函數(shù)名換成別的就好了