<head></head>
<body>
<!-- dialog -->
<button onclick=dakai()></button>
<dialog id='dialog'>this is a dialog</dialog>
<script>
var dakai=function(){
var x=document.getElementById("dialog").open
console.log(x)
if(x){
document.getElementById("dialog").removeAttribute('open')
}else{
document.getElementById("dialog").setAttribute('open','open')
}
</script>
</body>
</html>
代码如下:
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
<script>
// 创建按钮
var mybutton = document.createElement('button')
mybutton.type = "button"
mybutton.innerText = "点我"
document.body.appendChild(mybutton)
// 监听点击事件
mybutton.addEventListener("click", function(event) {
for (var i = 0 i < 3 i++) {
alert("hello world !")
}
}, false)
</script>
</html>
这个没有搞过,但是可以给个思路:在页面上添加下面的js试试,即把js自己的alert、confirm、prompt给覆盖掉。
var alert=function(){return 1}var confirm=function(){return 1}
var prompt=function(){return 1}