<HTML>
<head>
<meta charset="utf-8">
</head>
<body>
<pre id="rabbit">
|\ /|
\|_|/
/. .\
=\_Y_/=
{>o<}
</pre>
<button onclick="hide()">Hide()</button>
<script>
function hide(){
let event = new CustomEvent("hide", {
cancelable:true
});
if(!rabbit.dispatchEvent(event)) {//if it is not dispatched
alert('The action was prevented by a handler');
} else {//if it is dispatched, the tag is hidden as supposed to
rabbit.hidden = true;
}
}
rabbit.addEventListener('hide', function(event) {
if(confirm("Call preventDefault?")) {
event.preventDefault();
}
});
</script>
</body>
</HTML>
<head>
<meta charset="utf-8">
</head>
<body>
<pre id="rabbit">
|\ /|
\|_|/
/. .\
=\_Y_/=
{>o<}
</pre>
<button onclick="hide()">Hide()</button>
<script>
function hide(){
let event = new CustomEvent("hide", {
cancelable:true
});
if(!rabbit.dispatchEvent(event)) {//if it is not dispatched
alert('The action was prevented by a handler');
} else {//if it is dispatched, the tag is hidden as supposed to
rabbit.hidden = true;
}
}
rabbit.addEventListener('hide', function(event) {
if(confirm("Call preventDefault?")) {
event.preventDefault();
}
});
</script>
</body>
</HTML>
댓글
댓글 쓰기