日期:2014-05-16  浏览次数:20287 次

按钮代替链接 跳转前提示问题
我希望用按钮代替链接,在链接前弹出提示。是否真的要跳转。

<input onClick="location.href='return   confirm('真的要跳转吗?')"; material_out_pdf.php?out_id=1'; " type="button" value="重印">

但按提示中的是后。跳转无效.请问如何解决呢?

------解决方案--------------------
a连接也可以控制的
<a id="a" href="http://www.csdn.net/" target="_blank">csdn</a>
document.getElementById("a").onclick = function() {
    return confirm("是否跳转");
};
input的话
<input onClick="if(confirm('真的要跳转吗?')){location.href='http://www.csdn.net/'}"; material_out_pdf.php?out_id=1'; " type="button" value="重印">
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>test.html</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script>
function go(){
var res = confirm('是否跳转');
if(res){
window.location.href='http://www.baidu.com'
}else{
//..什么都不做
}
}
</script>
  </head>
  <body>
   <a href="#" onclick="go()">go</a>
  </body>
</html>