我有这个清单:
<?php if (!$this->ion_auth->in_group(array('Patient'))) { ?>
<li class="">
<div>
<label for="exampleInputEmail1"><?php echo lang('categorie'); ?></label>
<select id="tableSelector" onchange="showTable()" class="form-control">
<option value="select">SELECT</option>
<option value="femmeEnceinte">Femme enceinte</option>
<option value="personnels">Personnel</option>
<option value="autres">Autres</option>
</select>
</div>
</li>
<?php } ?>
字符串
如果我们选择列表中的第一个元素,第一个表格会显示,如果我们选择第二个元素,第二个表格会显示,第三个也是一样。
这是三个表:
<?php if (!$this->ion_auth->in_group(array('Patient'))) { ?>
<div id="femmeEnceinte" class="tab-pane"> <div class="">
<!--First table (femmeEnceinte) start-->
<div class="adv-table editable-table " id="femmeEnceint" style="display: none">
<table class="table table-striped table-hover table-bordered" id="table_femmeE">
<thead>
<tr>
<th><?php echo lang('patient_id'); ?></th>
<th><?php echo lang('name'); ?></th>
<th><?php echo lang('cas'); ?></th>
<th><?php echo lang('birth_date'); ?></th>
<th><?php echo lang('address'); ?></th>
<?php if ($this->ion_auth->in_group(array('Doctor', 'admin', 'Receptionist'))) { ?>
<th><?php echo lang('department'); ?></th>
<th><?php echo lang('sex'); ?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<style>
.img_url{
height:20px;
width:20px;
background-size: contain;
max-height:20px;
border-radius: 100px;
}
</style>
<?php foreach ($patients as $patient) { ?>
<tr class="">
<td><?php echo $patient->id; ?></td>
<td><?php echo $patient->name; ?></td>
<td><?php echo $patient->phone; ?></td>
<td><?php echo $patient->birthdate; ?></td>
<td><?php echo $patient->address; ?></td>
<?php if ($this->ion_auth->in_group(array('Doctor', 'admin', 'Receptionist'))) { ?>
<td><?php echo "Département"; // echo " "; $patient->department ?></td>
<td> <?php echo $patient->sex; ?></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!--first table (femmeEnceinte) end-->
<!--second table (personnel) start-->
<div class="adv-table editable-table " style="display: none" id="personnel">
<table class="table table-striped table-hover table-bordered" id="editable-sample">
<thead>
<tr>
<th><?php echo lang('patient_id'); ?></th>
<th><?php echo lang('name'); ?></th>
<th><?php echo lang('phone'); ?></th>
<?php if ($this->ion_auth->in_group(array('admin', 'Accountant', 'Receptionist'))) { ?>
<th><?php echo lang('sex'); ?></th>
<?php } ?>
<th class="no-print"><?php echo lang('options'); ?></th>
</tr>
</thead>
<tbody>
<style>
.img_url{
height:20px;
width:20px;
background-size: contain;
max-height:20px;
border-radius: 100px;
}
</style>
</tbody>
</table>
</div>
<!--Second table (personnel) end-->
<!--Third table (autres) start-->
<div class="adv-table editable-table " id="divautres" id="autre">
<table class="table table-striped table-hover table-bordered" id="table_autres">
<thead>
<tr>
<th><?php echo lang('patient_id'); ?></th>
<th><?php echo lang('name'); ?></th>
<th><?php echo lang('cas'); ?></th>
<th><?php echo lang('birth_date'); ?></th>
<th><?php echo lang('address'); ?></th>
<th><?php echo lang('sex'); ?></th>
</tr>
</thead>
<tbody>
<style>
.img_url{
height:20px;
width:20px;
background-size: contain;
max-height:20px;
border-radius: 100px;
}
</style>
<?php foreach ($patients as $patient) { ?>
<tr class="">
<td><?php echo $patient->id; ?></td>
<td><?php echo $patient->name; ?></td>
<td><?php echo $patient->phone; ?></td>
<td><?php echo $patient->birthdate; ?></td>
<td><?php echo $patient->address; ?></td>
<td> <?php echo $patient->sex; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!--Third table (autre) end-->
</div>
</div>
<?php } ?>
型
这是显示和隐藏表的代码。我希望这段代码只限于这三个表。因为页面上有其他不受SELECT选项影响的表。那么它们就不能被隐藏和显示
function showTable() {
// Hide all tables
var tables = document.getElementsByClassName("adv-table");
for (var i = 0; i < tables.length; i++) {
tables[i].style.display = "none";
}
// Show the selected table
var selectedTableId = document.getElementById("tableSelector").value; document.getElementById(selectedTableId).style.display = "block";
}
型
我被建议使用JavaScript,即使我实际上对它一无所知。
1条答案
按热度按时间1bqhqjot1#
你已经很接近了。你可以试试下面的代码:
字符串
我没试过,但应该能用。