Javascript 显示图片时禁用提交按钮

Javascript 显示图片时禁用提交按钮,javascript,jquery,Javascript,Jquery,我创建了一个用户可以上传照片的功能。上传后,用户可以查看照片 显示照片时,应禁用“提交”按钮 $(document).ready(function () { if(imageDisplayed){ button.attr('disabled', 'disabled'); ) }) 我有两个控制器页面:照片列表页面和上传页面 以下是我尝试过的: <button class="btn" id="submit"> Sub

我创建了一个用户可以上传照片的功能。上传后,用户可以查看照片

显示照片时,应禁用“提交”按钮

 $(document).ready(function () {
   if(imageDisplayed){         
      button.attr('disabled', 'disabled');           
   )
 })
我有两个控制器页面:照片列表页面和上传页面

以下是我尝试过的:

<button class="btn" id="submit"> Submit</button>

<script type="text/javascript">
  "use strict";

    $(document).ready(function () {
       $("#submit").click(function () {           
         button.attr('disabled', 'disabled');           
     });
   })
提交
“严格使用”;
$(文档).ready(函数(){
$(“#提交”)。单击(函数(){
button.attr('disabled','disabled');
});
})

这是因为在
点击
提交
按钮的
时,页面被刷新

正确的方法是,如果显示
图像
,则禁用
按钮

 $(document).ready(function () {
   if(imageDisplayed){         
      button.attr('disabled', 'disabled');           
   )
 })
试试这个:

使用Javascript

点击
函数禁用(){
document.getElementById(“按钮”).disabled=true;
}
使用JQuery

点击
$(文档).ready(函数(){
$(“#按钮”)。单击(函数(){
$(this.prop('disabled',true);
});
});

这是经过检查的代码,工作正常。

可能缺少变量
按钮
声明您能给我举个例子吗?关于“imageDisplayed”,我必须声明它吗?是的,你可以检查显示图像的HTML部分,也可以保留任何标记。为此,你可以共享你的HTML和图像显示代码吗?但这是为了上传照片,只需在按钮中添加id添加使用它并更改代码中的id名称。就是这样!
<button id="button" onclick="disable()">Click</button>

<script>
  $(document).ready(function(){
    $('#button').click(function(){
       $(this).prop('disabled', true);
    });
 });
</script>