Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如果选择了图像,则允许单击按钮_Jquery - Fatal编程技术网

Jquery 如果选择了图像,则允许单击按钮

Jquery 如果选择了图像,则允许单击按钮,jquery,Jquery,我有一个表格上传图像 我想禁用此按钮并仅在用户选择某个文件时启用它。有什么办法可以让它工作吗 <form action="/upload.php" id="upload" method="POST"> <input type="file" name="photo" id="photo" class="file_input"> <input type="submit" value="Upload" id="upload_btnb" disabled&g

我有一个表格上传图像

我想禁用此按钮并仅在用户选择某个文件时启用它。有什么办法可以让它工作吗

<form action="/upload.php" id="upload" method="POST">
    <input type="file" name="photo" id="photo" class="file_input">
    <input type="submit" value="Upload" id="upload_btnb" disabled>
</form>

用户选择文件时如何启用按钮?

请尝试以下操作

$('#photo').change(function(){
   $('#upload_btnb').prop('disabled', false);
});
试着像下面这样

$('#photo').change(function(){
   $('#upload_btnb').prop('disabled', false);
});
试着这样做: HTML:

试着这样做: HTML:


可能重复@RejithRKrishnan我不想验证图像,只想在选择图像时启用按钮!这意味着您需要检查添加的文件是否为图像,对吗?@RejithRKrishnan否,如果用户需要,可以添加exe。。。之后,我想启用按钮。。。PHP将解决exe问题…可能重复@RejithRKrishnan我不想验证图像,只想在选择图像时启用按钮!这意味着您需要检查添加的文件是否为图像,对吗?@RejithRKrishnan否,如果用户需要,可以添加exe。。。之后,我想启用按钮。。。PHP将解决exe问题…使用
prop()
代替
attr()
使用
prop()
代替
attr()
$(document).ready(function(){
    $('input:file').change(function(){
        if ($(this).val()) {
           $('input:submit').attr('disabled',false);
           // or, as has been pointed out elsewhere:
           // $('input:submit').removeAttr('disabled'); 
        } 
    });
});