2009-08-13 44 views
0

我试图创建一个提示框,提示用户是否删除或取消,当我点击删除按钮它工作正常,但当我再次点击取消我的网页是关闭的。下面是封闭的功能。请帮忙。JavaScript删除或取消

<SCRIPT language="JavaScript"> 
<!-- 
function go_there() 
{ 
    var where_to= confirm("Do you really want to go to this page??"); 

    if (where_to== true) 
    { 
     //closes the page 
    } 
    else 
    { 
     //Cancel the page and do not close the page 
    } 
} 
//--> 
</SCRIPT> 
+0

您可以发布被点击时取消执行的代码。 else部分中的代码。 – rahul 2009-08-13 05:37:57

+0

嘿,如果我的解决方案为你工作,你可以把它标记为接受答案。 – Saeros 2009-08-22 05:25:16

回答

2

在这种情况下,最常见的错误可能是你会在点击取消省略

return false 

,它应该返回false。这可能是一个合理的解决方案。 在你的情况下,要么给一个return语句,要么定义一个什么都不做的空函数。

+0

感谢Saeros ...它为我工作。谢谢 – pradeep 2009-08-13 05:39:59

0
<SCRIPT language="JavaScript"> 
<!-- 
function go_there() 
{ 
    if (confirm("Do you really want to go to this page??")) { 
     //closes the page 
    } else 
     return false; 
} 
//--> 
</SCRIPT> 
0
<script language="JavaScript"> 
<!-- 
function go_there() { 
    if(!confirm('Do you really want to go to this page?')) { 
     return false; //Cancel the page and do not close the page 
    } 
} 
--> 
</script>