我有一个输入文件选择器,我想知道如果未选择文件,模式何时关闭。我只知道只有在选择文件或更改文件时才有效的更改
<input type="file" id="selector">
$("#selector").on("change", function() {
//Changed
});
Run Code Online (Sandbox Code Playgroud)
小智 2
尝试这个
<input type='file' id='testfile' style='display:none' />
<button onclick='document.getElementById("testfile").click()'>Upload</button>
<script>
var testfile = document.getElementById('testfile')
testfile.onclick = focus();
function focus()
{
document.body.onfocus = invoke();
}
function invoke()
{
if(testfile.value.length)
{
alert('has file');
}
else {alert('empty')}
</script>
Run Code Online (Sandbox Code Playgroud)