Validate input type=file with onBlur

帅比萌擦擦* 提交于 2019-12-02 17:54:35

问题


I'm able to use onBlur to validate type=text or textarea inputs, however I haven't been able to get the same to work for type=file.

This works:

<input type='text' name='sometextfield' size=30 class='input' onBlur="alert('Frell me dead, it works!');"

This does not (no error):

  <input type='file' name='file_upload' size=30 class='input' onBlur="alert('Frell me dead, it works!');"> 

What is the trick to validating type=file input boxes, on the fly? I'd like to do this in vanilla Javascript. I'm testing with Chrome 17.0.963.56 and Firefox 10.0.2 under Ubuntu.

Thanks for tips/pointers.


回答1:


Try using the onchange-Event:

<input type="file" name="file_upload" size="30" class="input" onchange="alert('Frell me dead, it works!');">

Demo: http://jsfiddle.net/TimWolla/azvGP/



来源:https://stackoverflow.com/questions/9607354/validate-input-type-file-with-onblur

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!