2016-05-17 42 views
0

這是我的PHP文件中的文本輸入:按鈕,在JS

<input style="text-align: center; max-width: 500px; margin-top: 0px;" type="text" placeholder="Paste your links here separated by a space" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Paste your links here separated by a space'" name='links' id='links' /> 
<!--lilbanner--> 
<BR> 
<button class="button alt" id="submit" type="submit"> 
    <?php printf($obj->lang['sbdown']); ?> 
</button> 
&nbsp;&nbsp;&nbsp; 

我想要的按鈕與文字輸入是空被禁用,當用戶鍵入文本並刪除它,它會再次清空,意味着按鈕將被禁用。我有以下的代碼,因爲我從我的其他網站想它的工作原理完全,但出於某種原因,它不工作(空文本輸入=鍵..)

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('.submit').prop('disabled', true); 
     $('#link').change(function() { 
      $('.submit').prop('disabled', this.value == "" ? true : false); 
     }) 
    }); 
</script> 

你能幫助我嗎?提前致謝!

+0

我沒有任何東西代替我知道,但它仍然不工作 –

+0

最簡單的發現可能是解決辦法:您輸入的ID是'links'而比你用於更改事件處理程序的鏈接 – devnull69

+0

Aaaaand:你的按鈕的ID有'submit'而不是'submit'類,你在更改禁用屬性時使用 – devnull69

回答

0

你的選擇是錯誤的,看的修補程序:

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#submit').prop('disabled', true); 
     $('#links').change(function() { 
     $('#submit').prop('disabled', this.value == "" ? true : false); 
     }) 
    }); 
    </script> 

Plunker:https://plnkr.co/edit/ETJiPg6BKDNkqbGHXCfk?p=preview

2

你去那裏。你想「KEYUP」和「粘貼」,而不是「變」:

$(document).ready(function() { 
    $('#submit').prop('disabled', true); 
    $('#links').bind('keyup paste', function() { 
     $('#submit').prop('disabled', this.value == "" ? true : false); 
    }) 
}); 
+0

的答案檢查小提琴:https://jsfiddle.net/dwvamy4w/ –