4
我有一個輸入文件選擇器,我想知道何時模式正在關閉,如果沒有選擇一個文件。我只知道當選擇一個文件,該文件只適用或改變有可能知道文件輸入對話框何時關閉?
<input type="file" id="selector">
$("#selector").on("change", function() {
//Changed
});
我有一個輸入文件選擇器,我想知道何時模式正在關閉,如果沒有選擇一個文件。我只知道當選擇一個文件,該文件只適用或改變有可能知道文件輸入對話框何時關閉?
<input type="file" id="selector">
$("#selector").on("change", function() {
//Changed
});
當打開的對話框中試試這個
<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>
的變化,它變得專注,所以瀏覽器窗口失去焦點。關閉對話框後,焦點將恢復。您必須在window
上訂閱focus
事件,但由於許多原因,窗口可能會丟失並獲得焦點,所以如果對話框已打開,則必須保留一個標記。
下面的代碼工作在:
並且不起作用:
function now() {
return window.performance ? performance.now() : +new Date
}
var isFileDialogOpened = false;
var input = document.querySelector('input');
input.addEventListener('click', function (e) {
console.log('clicked', now())
isFileDialogOpened = true
})
input.addEventListener('blur', function (e) {
console.log('input blur', now())
isFileDialogOpened = true
})
window.addEventListener('focus', function (e) {
if (isFileDialogOpened) {
console.log('closed (window got focus)', now())
isFileDialogOpened = false
}
})
<input type=file>
你想知道當用戶按下取消按鈕? –
是的。但是是選擇文件的輸入。它打開默認的操作系統對話框來打開文件 –
您正在使用引導模式? –