当前位置: 动力学知识库 > 问答 > 编程问答 >

How to disable button in PHP using JQUERY?

问题描述:

I have a button in my application :

<button name="download" id="download" type="submit" class="btn primary" style="margin:0;">Next</button>

How can I disable this button and re-enable it using JQuery ?

I tried below code but it doesn't works.

$('#download').attr('disabled', 'disabled');

$('#download').removeAttr('disabled');

TIA :)

网友答案:

Try something like this,

<!DOCTYPE html>
<html>
<head>
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
    <script type='text/javascript'>
    //<![CDATA[ 
      $(window).load(function(){
        $('button#download').prop('disabled', true);
        alert('hello');
        $('button#download').removeAttr('disabled');
      });
    //]]>  
    </script>
</head>
<body>
  <button name="download" id="download" type="submit" class="btn primary" style="margin:0;">Next</button>
</body>
</html>
网友答案:

Below code if you have text box that is empty the submit button ill be disbaled if the textbox is not empty submit button not disabled

   $(document).ready(function() {
         $('input[type="submit"]').attr('disabled','disabled');
         $('input[type="text"]').keyup(function() {
            if($(this).val() != '') {
               $('input[type="submit"]').removeAttr('disabled');
            }
         });
     });
分享给朋友:
您可能感兴趣的文章:
随机阅读: