2016-11-10 56 views
0

當表列selection的值不是none時,我需要隱藏所有按鈕。然後如何在PHP代碼中使用javascript或jquery禁用按鈕。歡迎提出建議,使用JavaScript代碼或jQuery中的php代碼來完成此任務。我的按鈕列表如下。如何在PHP代碼中使用javascript或jquery禁用按鈕

<?php include("db_conection.php");$sql = "SELECT selection FROM users"; 
$result = $dbcon->query($sql); 
if ($result->num_rows > 0) { 
while($row = $result->fetch_assoc()) { 
$value = $row['selection']; 
if($value !='none'){ 
//need to add jquery or javascript here 
//$('button').attr("disabled", "disabled"); 
//$('button').text('Disabled');  
} 
} 
}?> 
<script type="text/javascript" > 
    // $('button').attr("disabled", "disabled"); 
    // $('button').text('Disabled'); 
    < /script> 

    <tr> 
     <td> 
     <button type="button" class="btn btn-primary" id="q1-1">Q1-1</button > 
    < /td> 
     <td> 
     <button type="button" class="btn btn-primary" id="q2-1">Q2-1</button > 
    < /td> 
     <td> 
     <button type="button" class="btn btn-primary" id="q3-1">Q3-1</button > 
    < /td> 
     <td> 
     <button type="button" class="btn btn-primary" id="q4-1">Q4-1</button > 
    < /td> 
    </tr > 

回答

0

嘗試先通過值在文本元素

<input type"text" id="sampleValue" value="<?php echo($value)> // this will put the value in a text element. 

之後,您可以通過它的ID使用它在JQuery中。

<script type="text/javascript" > 
    if($('#sampleValue')!='none') { 
     $('button').attr("disabled", "disabled"); 
     $('button').text('Disabled'); 
    } 
</script>