【问题标题】:Hide/show table columns with jQuery使用 jQuery 隐藏/显示表格列
【发布时间】:2010-10-28 21:32:07
【问题描述】:

我目前正在开发一个新的 Magento 模板,但我遇到了 jQuery 的问题。

我当前的 app/design/frontend/default/blank/template/catalog/product/list.phtml 代码类似于以下(页面托管在这里:http://nordschleife.metaforix.net/118/118/index.php/panasonic.html

<table border="1">
  <tr>
    <th width="178">Image</th>
    <th width="84">Order Code</th>
    <th width="84">Description</th>
    <th width="69">Cell Origin</th>
    <th width="98">Capacity (mAh)</th>
    <th width="110"><p>Price</p>
      <p><?php echo $this->getChildHtml('currency2'); ?></p></th>
    <th width="39">Buy</th>
    <th width="131">Cell(s)</th>
    <th width="52">Voltage</th>
    <th width="49">Rating (Wh)</th>
    <th width="71">Part Number</th>
    <th id="chem" width="69">Chemistry</th>
    <th width="82"><p>Dimensions</p>
      <p>(LxWxH)</p></th>
    <th width="52">Weight (g)</th>
    <th width="37">Color</th>
  </tr>
   <?php $_iterator = 0; ?>
    <ol class="products-list" id="products-list">
    <?php foreach ($_productCollection as $_product): ?>
        <tr> 
        <td>
          <?php // Product Image ?>        
    </td>
         <td>
        <?php echo nl2br($_product->getSku()) ?>
         </td>
         <td>
            <?php // Product description ?>           
         </td>
         <td>
            <?php echo $_product->getAttributeText('country') ?>
         </td>
         <td>
            <?php echo $_product->getcapacity() ?>
         </td>
         <td>
            <?php echo $this->getPriceHtml($_product, true) ?>
         </td>
         <td>
            <?php //add to cart ?>
         </td>
         <td>
            <?php echo $_product->getcells() ?>
         </td>
         <td>
            <?php echo $_product->getvoltage() ?>
         </td>
         <td>
            <?php echo $_product->getrating() ?>
         </td>
         <td>
            <?php echo $_product->getmfgpartno(); ?>
         </td>
         <td>
            <?php //chemistry ?>
         </td>
         <td>
            <?php echo nl2br ($_product->getdimension()) ?>
         </td>
         <td>
            <?php echo (int)$_product->getweight() ?>
         </td>
         <td>
            <?php echo $_product->getAttributeText('color') ?>
         </td>
         </tr>       
        </div>
<?php endforeach; ?>
</table>

我想使用 jQuery 在页面上添加一个文本,允许用户单击并显示/隐藏表格的最后 5 列。

我已将它放在文件中(想先尝试隐藏 1 列),但显然它不起作用:

<script type="text/javascript">
    function show() {
        jQuery(".chem").show();
    }
    function hide() {
         jQuery(".chem").hide();
     }
 </script>
<p><div>
jQuery
<span onclick="show() ">(More)</span>
<span onclick="hide() ">(Hide)</span> </div></p>

【问题讨论】:

标签: jquery html magento


【解决方案1】:

您可以使用 td/th 索引隐藏一列:

$('#tableId td:nth-child(3), #tableId th:nth-child(3)').hide();

【讨论】:

  • 非常抱歉,我在哪里插入该代码,以及如何放置用户可以点击的内容?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多