weixin_33739523 2018-11-27 00:13 采纳率: 0%
浏览 34

显示的照片

How do I disable the submit button once the photos is displayed on the page? Anyone knows? Here's my code:

        if("#pic" == true){
         }
         else{
           $("#submit").click(function () {           
           var button = $(this);
           button.attr('disabled', 'disabled');           
          });

        }
  • 写回答

1条回答 默认 最新

  • weixin_33695082 2018-11-27 05:04
    关注

    here's the modified code

    $('#pic').on('load', function() {
      console.log("loaded");
      
      $('#submit').attr('disabled',true);
    })
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <img id="pic" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" />
    
    <button id="submit">hello</button>

    if the img source is improper it won't render and the load method is hence not called, so we are sure of the proper image source and after rendering it calls the Load method in which you can disable your button

    </div>
    
    评论

报告相同问题?