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');
}
});
});