如何使用JS做到页面关闭或跳转时的确认提示
1个回答
展开全部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="file:///D:/SublimeText3/Data/mylive.js"></script>
<title></title>
<style>
</style>
</head>
<body>
<button id="close">关闭</button>
<button id="go">跳转</button>
</body>
</html>
<script>
function Wed(id, txt,fn){
this.id = document.getElementById(id);
this.txt = txt;
this.fn = fn;
this.run(this.txt, fn);
}
Wed.prototype.run = function (txt,fn){
this.id.onclick = function (){
eval(fn);
}
}
new Wed('close','确认关闭?','window.close()');
new Wed('go','确认跳转?',"window.location = 'https://www.baidu.com'");
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询