Created
August 25, 2023 13:36
-
-
Save voidproc/519f4bcb8f0ceabe8a866a92d2b9e1c5 to your computer and use it in GitHub Desktop.
input[type=file]のcancelイベントが発火するか調べる用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>input cancel event</title> | |
</head> | |
<body> | |
<div> | |
<input type="file" id="f" name="f"> | |
</div> | |
<div> | |
<div id="log-list"></div> | |
</div> | |
<script> | |
function writeLog(text) { | |
const divLog = document.createElement('div'); | |
divLog.innerHTML = text; | |
const divLogList = document.getElementById('log-list'); | |
divLogList.appendChild(divLog); | |
console.log(text); | |
} | |
const input = document.getElementById("f"); | |
input.oncancel = function(e) { | |
writeLog('oncancel'); | |
}; | |
input.oninput = function(e) { | |
writeLog(e.target.files[0].name); | |
e.target.value = ''; | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment