使'file'输入元素为必填(必填) [英] Making 'file' input element mandatory (required)
本文介绍了使'file'输入元素为必填(必填)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要(一个HTML)'file'输入元素是强制的:像
I want to make (an HTML) 'file' input element mandatory: something like
<input type='file' required = 'required' .../>
但它不工作。
我看到此 WW3 手册,其中说明必需属性是HTML 5的新功能。但是我不在我正在工作的项目中使用HTML 5,它不支持新功能。
I saw this WW3 manual which states 'required' attribute is new to HTML 5. But I am not using HTML 5 in the project I am working which doesn't support the new feature.
任何想法? >
Any idea?
推荐答案
你可以这样使用Jquery: -
You can do it using Jquery like this:-
<script type="text/javascript">
$(document).ready(function() {
$('#upload').bind("click",function()
{
var imgVal = $('#uploadfile').val();
if(imgVal=='')
{
alert("empty input file");
return false;
}
});
});
</script>
<input type="file" name="image" id="uploadfile" size="30" />
<input type="submit" name="upload" id="upload" class="send_upload" value="upload" />
这篇关于使'file'输入元素为必填(必填)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文