[英]How do I run JS code when a user uploads files?
I want the message You uploaded a file!
我想要You uploaded a file!
to pop up after I select a file.选择文件后弹出。
<html>
<head>
<script type="text/javascript">
$(document).ready(function() {
$("#uploadme").click(function() {
alert("You uploaded a file!")
});
});
</script>
</head>
<body>
<input type="file" id="uploadme"/>
</body>
</html>
Please consider adding a comment if you think this post can be improved.如果您认为这篇文章可以改进,请考虑添加评论。
I managed to solve this problem using a listener.我设法使用侦听器解决了这个问题。
<input type="file" id="uploadme">
<script>
const fileSelector = document.getElementById('uploadme');
fileSelector.addEventListener('change', (event) => {
alert('You uploaded a file!')
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.