利用jquery实现的全选效果代码,实际上我感觉直接用js好像更容易些。不过这样对于jquery的操作可以更熟悉。
多选效果如下图
代码如下:
复制代码 代码如下:
<script type="text/javascript"><!--
$(document).ready(function() {
$("#selectall").click(selectAll);
});
function selectAll() {
var checked = $("#selectall").attr("checked");
$(".selectable").each(function() {
var subchecked = $(this).attr("checked");
if (subchecked != checked)
$(this).click();
});
}
// --></script>
<table>
<thead>
<tr>
<th ><input type="checkbox" /></th>
<th>Item Name</th>
<th>UM</th>
<th>Ordered Qty</th>
<th>Received Qty</th>
<th>Quantity</th>
<th>Remark</th>
</tr>
</thead>
<?php
$i = 1;
foreach($this->details as $item) {
echo "<tr>\n";
echo "<td><input type='Checkbox' value='" . $item["item_id"] . "' /></td>\n";
//item name
echo "<td >" . $item["item_name"] . "<input type='hidden' value='" . $item["item_id"] . "' /><input type='hidden' value='" . $item["item_name"] . "' /></td>\n";
//unit
echo "<td>" . $item["unit_name"] . "</td>\n";
//Ordered Qty
echo "<td>" . $item["quantity"] . "</td>\n";
//Received Qty
echo "<td>" . $item["received_qty"] . "</td>\n";
//Quantity
echo "<td><input type='text' MaxLength='4' OnKeyPress='EnsureDecimal(this)'/></td>\n";
//Remark column
echo "<td><input type='text' MaxLength='30'></td>";
echo "</tr>\n";
$i++;
}
?>
</table>
局部多选如下图
代码
复制代码 代码如下:
<script type="text/javascript"><!--
function selectAllMenu(cmb) {
var checked = cmb.checked;
$(".selectable[model=" + cmb.model + "]").each(function() {
var subchecked = $(this).attr("checked");
if (subchecked != checked)
$(this).click();
});
}
// --></script>
<?php
if (isset($this->user)) {
echo "<h3>Privilege Setting For User " . $this->user ."</h3>";
}
elseif (isset($this->role)) {
echo "<h3>Privilege Setting For Role " . $this->role . "</h3>";
}
else {
echo "<h3>Privilege Setting</h3>";
}
?>
<form method="post" action="<?php echo $this->baseUrl . '/admin/privilege/save'; ?>">
<center>
<table>
<?php
$model_name = "";
foreach($this->privileges as $privilege) {
if ($model_name != $privilege['model_name']) {
$model_name = $privilege['model_name'];
echo "<tr>\n";
echo " <td><input model='$model_name' type='checkbox'/></td>\n";
echo " <td colspan='2'><b>$model_name</b></td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo " <td></td>\n";
echo " <td><input model='$model_name' type='checkbox'/></td>\n";
echo " <td>" . $privilege['display_text'] . "</td>\n";
echo "</tr>\n";
}
?>
</table>
</center>
<div>
<?php
$button_panel = new ButtonPanel();
$button_panel->setButtonAlign("center");
$button_panel->addButton(array("text" => "Save", "type" => "submit"));
$button_panel->addButton(array("text" => "Reset", "type" => "reset"));
$button_panel->addButton(array("text" => "Back", "onclick" => "window.history.back();"));
$button_panel->render();
?>
</div>
</form>
您可能感兴趣的文章: