`

a标签点击跳转或表单提交前弹出确认框

 
阅读更多

转载

①html

 <a href="http://www.iteye.com" onclick="if(confirm('确认iteye吗?')==false) return false;">iteye</a>

 

②js

function foo(){
    if(confirm("确认iteye吗?")){
	    return true;
	}
	return false;
 }  

 

标签改为:

<a href="http://www.iteye.com" onclick="return foo();">iteye</a>

 

1.我们这里写的是a标签点击提交出现的跳转事件,

   表单提交时,也是这么做。

2.必须将return 写在标签里,

   否则不管你是否点击确定,都会出现跳转和表单内提交。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics