how to alert if input type file is empty !?
如果输入类型文件为空,如何提醒!
this is my jquery code but i didnt know how to get the value
这是我的jquery代码,但我不知道如何获得该值
$('.upload').live("click",function()
{
var imgVal = $('#uploadImage').val();
if(imgVal=='')
{
alert("empty input file");
}
return false;
});
<input type="file" name="image" id="uploadImage" size="30" />
<input type="submit" name="upload" class="send_upload" value="upload" />
3 个解决方案
#1
42
<script type="text/javascript">
$(document).ready(function() {
$('#upload').bind("click",function()
{
var imgVal = $('#uploadImage').val();
if(imgVal=='')
{
alert("empty input file");
}
return false;
});
});
</script>
<input type="file" name="image" id="uploadImage" size="30" />
<input type="submit" name="upload" id="upload" class="send_upload" value="upload" />
#2
6
There should be
应该有
$('.send_upload')
but not $('.upload')
但不是$('。upload')
#3
3
HTML Code
HTML代码
<input type="file" name="image" id="uploadImage" size="30" />
<input type="submit" name="upload" class="send_upload" value="upload" />
jQuery Code using bind method
使用bind方法的jQuery代码
$(document).ready(function() {
$('#upload').bind("click",function()
{ if(!$('#uploadImage').val()){
alert("empty");
return false;} }); });
#1
42
<script type="text/javascript">
$(document).ready(function() {
$('#upload').bind("click",function()
{
var imgVal = $('#uploadImage').val();
if(imgVal=='')
{
alert("empty input file");
}
return false;
});
});
</script>
<input type="file" name="image" id="uploadImage" size="30" />
<input type="submit" name="upload" id="upload" class="send_upload" value="upload" />
#2
6
There should be
应该有
$('.send_upload')
but not $('.upload')
但不是$('。upload')
#3
3
HTML Code
HTML代码
<input type="file" name="image" id="uploadImage" size="30" />
<input type="submit" name="upload" class="send_upload" value="upload" />
jQuery Code using bind method
使用bind方法的jQuery代码
$(document).ready(function() {
$('#upload').bind("click",function()
{ if(!$('#uploadImage').val()){
alert("empty");
return false;} }); });