从下拉列表中选择类别时显示相关属性?

时间:2013-07-12 06:49:23

标签: php javascript jquery ajax magento-1.7

我想根据下拉列表中的选择显示属性。为此我写了一些代码,它在本地工作正常(Magento外面),现在我想在magento旁边解决它...我正在使用Magento CE 1.7

这是我的代码(外侧magento代码)

本地代码: -

    <html>
    <head>
        <title></title>
    </head>
<body>
    <select id="xyz">
        <option value="Men">Men</option>
        <option value="Women">Women</option>
        <option value="Kids">Kids</option>
        <option value="Furniture">Furniture</option>
        <option value="Books">Books</option>
    </select>
  <div id="Men" class="group">
    Color<input id="color" name="color" type="text">
    Size<input id="size" name="size" type="text">
  </div>
  <div id="Women" class="group">
    Size<input id="size" name="size" type="text">
  </div>
  <div id="Kids" class="group">
    Color<input id="color" name="color" type="text">
  </div>
  <div id="Furniture" class="group">
    Color<input id="color" name="color" type="text">
    Size<input id="size" name="size" type="text">
    Finishing<input id="finishing" name="finishing">
  </div>
  <div id="Books" class="group">
    ISBN<input id="isbn" name="isbn" type="text">
  </div>
  </body>
    <script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script language="JavaScript" type="text/javascript">
        $(document).ready(function () {
            $('.group').hide();
        $('#Men').show();
        $('#xyz').change(function () {
            $('.group').hide();
            $('#'+$(this).val()).show();
        })
         });
    </script>
    </script>
</html>

是的现在我想在magento Dropdown类别中应用相同的东西为此我写了这段代码但它不工作为什么?我做错了什么?

Magento代码: -

  <tr>
<td class="tdpadfirst">
   <label for="category" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Product Category') ?>:</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
</td>
<td class="tdpadsec">
    <?php $_helper = Mage::helper('catalog/category') ?>
    <?php $_categories = $_helper->getStoreCategories() ?>
    <?php $currentCategory = Mage::registry('current_category') ?>
    <?php if (count($_categories) > 0): ?>
        <select id="xyz" class="myinput-text required-entry widthinput" name="category">
        <option value="">--Select Categories--</option>
        <?php $_helper = Mage::helper('catalog/category') ?>
        <?php $_categories = $_helper->getStoreCategories() ?>
        <element onclick="<?php $currentCategory = Mage::registry('current_category') ?>">
        <?php if (count($_categories) > 0): ?>
            <?php foreach($_categories as $_category): ?>
                <option value="<?php echo $_category->getId() ?>">
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                <?php echo $_category->getName() ?></a>
                </option>
            <?php endforeach; ?>
        <?php endif; ?>
    <?php endif; ?>
</td>

    <div id="Mens" class="group">
   <tr>
    <td class="tdpadfirst">
        <label for="size" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Size') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </td>
    <td class="tdpadsec">
        <input type="size" class="required-entry widthinput" name="size" id="size" value="<?php echo $size ?>"/>
        <?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: 10,20) ') ?>
    </td>
   </tr>
   <tr>
    <td class="tdpadfirst">
        <label for="seller_colour" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Color') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </td>
    <td class="tdpadsec">
        <input type="seller_colour" class="required-entry widthinput" name="seller_colour" id="seller_colour" value="<?php echo $seller_colour ?>"/>
        <?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: White,Black) ') ?>
    </td>
   </tr>
</div>
<div id="Womens" class="group">
   <tr>
    <td class="tdpadfirst">
        <label for="size" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Size') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </td>
    <td class="tdpadsec">
        <input type="size" class="required-entry widthinput" name="size" id="size" value="<?php echo $size ?>"/>
        <?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: 10,20) ') ?>
    </td>
   </tr>
</div>
<div id="Kids" class="group">
   <tr>
    <td class="tdpadfirst">
        <label for="seller_colour" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Color') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </td>
    <td class="tdpadsec">
        <input type="seller_colour" class="required-entry widthinput" name="seller_colour" id="seller_colour" value="<?php echo $seller_colour ?>"/>
        <?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: White,Black) ') ?>
    </td>
   </tr>
</div>
<div id="furniture" class="group">
   <tr>
    <td class="tdpadfirst">
        <label for="seller_colour" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Color') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </td>
    <td class="tdpadsec">
        <input type="seller_colour" class="required-entry widthinput" name="seller_colour" id="seller_colour" value="<?php echo $seller_colour ?>"/>
        <?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: White,Black) ') ?>
    </td>
   </tr>
</div>
    <script language="JavaScript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
    $('.group').hide();
    $('#Mens').show();
    $('#category').change(function () {
    $('.group').hide();
    $('#'+$(this).val()).show();
    })
    });
</script>
</script>

我在这里使用Magento CE 1.7

任何想法?

1 个答案:

答案 0 :(得分:1)

似乎你的布局很笨,

<div id="Kids" class="group">
   <tr>
    <td class="tdpadfirst">
        <label for="seller_colour" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Color') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </td>
    <td class="tdpadsec">
        <input type="seller_colour" class="required-entry widthinput" name="seller_colour" id="seller_colour" value="<?php echo $seller_colour ?>"/>
        <?php echo Mage::helper('marketplacepartner')->__('For multiple values separate with , (Example: White,Black) ') ?>
    </td>
   </tr>
</div>

我不确定你如何将<tr>放在<div>标签内?请在div结构中重新组织它们

<table>
<tr><td>

your category divs

</td>
</tr>
</table>