单击按钮时显示隐藏对象(PHP with javaScript)

时间:2016-10-19 10:13:42

标签: javascript php html onclick hidden

如何使用PHP计数器通过javaScript显示隐藏文本字段。我将这段代码用HTML结合PHP:

   <?php if(isset($prior)): foreach($prior as $row): ?>
   <tr>
         <td> <?php echo $row->priority?> </td>
         <td> <?php echo $row->priority_time?> </td>
         <td>
              <button type="button" class="btn btn-info btn-sm" onclick="">
                 <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
              </button>
              <input  type="text" id="" name="<?php echo $row->priority_id?>" hidden/>
         </td>
   </tr>
   <?php endforeach;?>
   <?php else:?>
         <p>Request Service not available</p>
   <?php endif;?>

3 个答案:

答案 0 :(得分:0)

首先给你的隐藏输入一个id,然后在你要删除隐藏类的函数里面:

var myButtonClasses = document.getElementById("theGivenId").classList; myButtonClasses.remove("hidden");

来源:classlist

答案 1 :(得分:0)

在PHP循环中:

<button type="button" class="btn btn-info btn-sm" onclick="showField(<?php echo $row->priority_id; ?>)">
  <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</button>

向页面添加JS功能:

function showField(name) {
  var el = document.querySelector('input[name="' + name + '"]');
  el.setAttribute('hidden', false);
}

答案 2 :(得分:0)

使用css作为输入隐藏,允许按钮点击调用javascript函数,您可以在其中执行其他任务  document.getElementById(&#34; theGivenId&#34;)。style.visibility =&#34; visible&#34;;