简体   繁体   English

使用onBlur验证输入类型=文件

[英]Validate input type=file with onBlur

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. 我可以使用onBlur来验证type = text或textarea输入,但是我无法为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? 快速验证type = file输入框的诀窍是什么? I'd like to do this in vanilla Javascript. 我想用香草Javascript来做。 I'm testing with Chrome 17.0.963.56 and Firefox 10.0.2 under Ubuntu. 我正在Ubuntu下使用Chrome 17.0.963.56和Firefox 10.0.2进行测试。

Thanks for tips/pointers. 感谢您的提示/指针。

Try using the onchange-Event: 尝试使用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/ 演示: http : //jsfiddle.net/TimWolla/azvGP/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM