私のデータベースには、product_categoryテーブルがあり、各製品カテゴリのproductsテーブルの製品があります。私は各製品カテゴリをボタンで動的に呼び出しました。それぞれの製品はHTMLテーブル上の特定の製品カテゴリの下にあります。各テーブルは、クラス 'hide'のために最初は非表示のままですが、jquery toggleClassでは、特定の商品カテゴリボタンがクリックされたときに表示されます。しかし、各テーブルにはモーダルを開くボタンがあり、いつでもその商品カテゴリを開いたままにしておきたい特定の商品テーブルをクリックします。 +領域内のスペースやテーブル自体をクリックしてボタンをクリックしなくても、閉じられます。どのようにして製品カテゴリボタンに制限することができますか?toggleClassで表示されるテーブルを作成するには、そのテーブル内のボタンをクリックすると開いたままになりますか?
product category buttons on a fresh page load
product displayed when a product category is clicked
<?php
global $number;
global $store_key;
global $product_set;
global $products;
global $query;
global $category;
$store_key = $_SESSION['store_key'];
//$branch_code = $_GET['branch_code'];
$query = "SELECT category_key FROM product_category WHERE store_key = '{$store_key}' ORDER BY category_name ASC";
$category_set = mysql_query($query);
if(!$category_set)
{
die("Database query failed: " . mysql_error().", ".$query);
}
while($category = mysql_fetch_array($category_set)){
?>
<ol id="chaps">
<li><button class="button button-3d button-leaf" ><?php echo ucfirst(get_category($category['category_key']));?></button>
<table id="datatable1" class="table table-striped table-bordered assignments hide" cellspacing="0" width="100%">
<caption>Product Details</caption>
<thead>
<tr>
<th>#</th>
<th>Product Name</th>
<th>Total Pieces</th>
<?php
if($_SESSION['store_key'] == $_SESSION['user_id']){
echo "<th>Action</th>";
}else{
echo "";
}
?>
</tr>
</thead>
<tfoot>
<tr>
<th>#</th>
<th>Product Name</th>
<th>Total Pieces</th>
<?php
if($_SESSION['store_key'] == $_SESSION['user_id']){
echo "<th>Action</th>";
}else{
echo "";
}
?>
</tr>
</tfoot>
<tbody>
<?php
global $number;
global $store_key;
global $product_set;
global $products;
global $query;
$store_key = $_SESSION['store_key'];
//$branch_code = $_GET['branch_code'];
if($_SESSION['store_key'] == $_SESSION['user_id']){
$query = "SELECT DISTINCT product_key,product_name FROM products WHERE store_key = '{$store_key}' AND category_key = '{$category['category_key']}' ORDER BY branch_code,product_name ASC";
$product_set = mysql_query($query);
if(!$product_set)
{
die("Database query failed: " . mysql_error().", ".$query);
}
}else{
$query = "SELECT DISTINCT product_key,product_name FROM products WHERE store_key = '{$store_key}' AND branch_code = '{$_SESSION['branch_code']}' AND category_key = '{$category['category_key']}' ORDER BY branch_code,product_name ASC";
$product_set = mysql_query($query);
if(!$product_set)
{
die("Database query failed: " . mysql_error().", ".$query);
}
}
$number = mysql_num_rows($product_set);
for($count=1;$count<=$number;$count++){
?>
<tr>
<?php $products = mysql_fetch_array($product_set); ?>
<?php echo "<td>{$count}</td>"; ?>
<?php echo "<td>".ucwords($products['product_name'])."</td>"; ?>
<?php
if($_SESSION['store_key'] == $_SESSION['user_id']){
echo "<td>".get_productPieces($products['product_key'])."</td>";
}else{
echo "<td>".get_branchPieces($products['product_key'])."</td>";
}
?>
<?php
if($_SESSION['store_key'] == $_SESSION['user_id']){
echo "<td width='20px'>
<a class='btn btn-warning btn-sm' id='branch' data-toggle=\"modal\" data-target='#add_branchProductModal' href='modals/add_branchProductModal.php?id3={$_SESSION['store_key']}' role='button'><span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></a>";?>
<!--<a class='btn btn-danger btn-sm' href='productdelete.php' role='button'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></a>-->
</td>
<?php
}else{
echo "";
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
</li>
</ol>
と私はその後、
<script>
$("#chaps > li").click(function() {
$(this).find("table.assignments").toggleClass('hide');
});
</script>
私は問題を解決するために実装しようとしたものを私の問題を発見する前に、それは安っぽいでなければなりません働いた私のjqueryのなぜなら、私はまだjqueryを学んでいるからです。
<script>
if($("#chaps > li").click()){
$(this).find("table.assignments").toggleClass('hide');
return true;
}else if($("#branch").click()){
$(this).find("table.assignments").toggleClass('hide');
return false;
}
</script>
を作業する必要があります私の 'hide'クラスを乗り越えることができる関数は、Product Categoryボタンだけをクリックするとテーブルを表示して閉じます。 –