如何禁用HTML代码

时间:2017-02-15 11:06:36

标签: javascript php jquery html

我有许多html输入标记,它接受用户输入并将其发布到变量代码:

<form method = "post" action=""select.php> 
    <input id="nol" style="width: 280px;" type="text" name="searchdisease" placeholder="type diagnosis one">
    <input id="nol" style="width: 280px;" type="text" name="searchdisease1" placeholder="type diagnosis two">
    <input id="nol" style="width: 280px;" type="text" name="searchdisease2" placeholder="type diagnosis three">
</form>

然后这个变量我将它附加到SQL查询以检索数据LIKE用户输入代码:

$search_disease = $_POST['searchdisease'];
$search_disease1 = $_POST['searchdisease1'];
$search_disease2 = $_POST['searchdisease2'];

$query="SELECT diagnosis FROM medications WHERE diagnosis LIKE '%$search_disease%'";
$result= $con->query($query);
$query1="SELECT diagnosis FROM medications WHERE diagnosis LIKE '%$search_disease1%'";
$result1= $con->query($query1);
$query2="SELECT diagnosis FROM medications WHERE diagnosis LIKE '%$search_disease2%'";
$result2= $con->query($query2);

,然后将结果回显给select标签。 代码:

<select id="disease" style="width: 40%;" name="tdisease">
   <option value="">Select Disease</option>
   <?php
       while ($row=$result->fetch_array(MYSQLI_ASSOC)) { 
   ?>
       <option value="<?php echo $row['ICD10']?>"><?php echo $row['diagnosis'];?> </option> 
   <?php } ?> 
</select>
<select id="disease" style="width: 40%;" name="tdisease1">
   <option value="">Select Disease</option>
   <?php
       while ($row=$result1->fetch_array(MYSQLI_ASSOC)) { 
   ?>
       <option value="<?php echo $row['ICD10']?>"><?php echo $row['diagnosis'];?> </option> 
  <?php } ?> 
</select>
<select id="disease" style="width: 40%;" name="tdisease2">
     <option value="">Select Disease</option>
     <?php
         while ($row=$result2->fetch_array(MYSQLI_ASSOC)) { 
     ?>
            <option value="<?php echo $row['ICD10']?>"><?php echo $row['diagnosis'];?> </option> 
     <?php } ?> 
</select>

所以我想知道当用户输入为空时如何使用JavaScript来禁用或隐藏选择标记?

2 个答案:

答案 0 :(得分:-1)

您可以在标签上添加事件监听器,这会将属性添加到选定的#34;禁用&#34;。
它看起来像:
const target = document.querySelector('<yourtag>'); target.value.length > 0 ? 'it is ok' : target.setAttribute('disabled', 'disabled');

答案 1 :(得分:-1)

每个输入的ID都应该不同。然后,​​

var val=$('#id-of-element').val;

选中为:if(val==" ")if(val==null) 当输入为空时,它将为空白。

您可以使用以下代码行来停用某个项目:

document.getElementById("id-of-selected-element").disabled="true";

隐藏:

document.getElementById("id-of-selected-element").style.display="none";