2017-07-03 114 views
0

如何基於PHP中的複選框選擇啓用/禁用列表。我必須啓用表單中顯示的列表,只有在複選框被選中的情況下。我無法找到如何在PHP中執行此操作。如果有人可以幫忙。如何根據複選框選擇禁用/啓用列表

我想禁用此列表,因爲我選中了複選框。

<html> 
<head> 
<script language="JavaScript"> 
function enable_text(status) 
{ 
status=!status; 
    document.f1.other_text.disabled = status; 
} 
</script> 
</head> 
<body onload=enable_text(false);> 

<form name=f1 method=post> 
<input type="checkbox" name=others onclick="enable_text(this.checked)" > 
<select name="Colors"> 
<option value="">Select...</option> 
<option value="R">Red</option> 
<option value="G">Green</option> 
<option value="B">Blue</option> 
</form> 

</body> 
</html> 
+2

在這裏展示您的代碼.... – GYaN

+1

添加您的代碼在這裏你試過了? – Narayan

+1

請添加您嘗試過的代碼。進一步的解釋很容易。 –

回答

0

$('#d-checkbox').click(function(e) { 
 
       if($(this).prop('checked') == true)$('#color').removeAttr("disabled"); 
 
       else $('#color').attr("disabled","disabled"); 
 
      });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<html> 
 
    <head> 
 
     </script> 
 
    </head> 
 
    <body> 
 
     <form name=f1 method=post> 
 
      <input type="checkbox" id="d-checkbox"> 
 
      <select name="Colors" id="color" disabled="disabled"> 
 
       <option value="">Select...</option> 
 
       <option value="R">Red</option> 
 
       <option value="G">Green</option> 
 
       <option value="B">Blue</option> 
 
      </select> 
 
     </form> 
 
     <script> 
 
      $('#d-checkbox').click(function(e) { 
 
       if($(this).prop('checked') == true)$('#color').attr("disabled","disabled"); 
 
       else $('#color').removeAttr("disabled"); 
 
      }); 
 
     </script> 
 
    </body> 
 
</html>

這裏是您的解決方案......

+1

謝謝@Gyandeep Sharma!一個簡單的問題,我想我一開始並不清楚,我希望列表在頁面加載時以及當我們點擊複選框時啓用。 ($(this).prop('checked')== true)()函數(e){0} { }如果($(this).prop('checked')== true) $('#color')。removeAttr(「disabled」); else $('#color')。attr(「enabled」,「enabled」);; }); '但它啓用後它不會獲得禁用,即使我取消選中該複選框。 – newbie

+0

編輯....請檢查 – GYaN

+1

謝謝@Gyandeep夏爾馬!它幫助了很多。 – newbie

-2

$('#d-checkbox').click(function(e) { 
 
       if($(this).prop('checked') == false)$('#color').attr("disabled","disabled"); 
 
       else $('#color').removeAttr("disabled"); 
 
      });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<html> 
 
    <head> 
 
     </script> 
 
    </head> 
 
    <body> 
 
     <form name=f1 method=post> 
 
      <input type="checkbox" id="d-checkbox"> 
 
      <select name="Colors" id="color"> 
 
       <option value="">Select...</option> 
 
       <option value="R">Red</option> 
 
       <option value="G">Green</option> 
 
       <option value="B">Blue</option> 
 
      </select> 
 
     </form> 
 
     <script> 
 
      $('#d-checkbox').click(function(e) { 
 
       if($(this).prop('checked') == false)$('#color').attr("disabled","disabled"); 
 
       else $('#color').removeAttr("disabled"); 
 
      }); 
 
     </script> 
 
    </body> 
 
</html>

+0

複製我的代碼..... – GYaN

相關問題