2016-11-10 52 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>