我在产品页面上的可配置选项块中工作,并在其底部插入一些JavaScript。我没有任何问题,但突然间,我在控制台上遇到了错误:“ und typeerror:无法读取未定义的属性'配置'。我认为这是一个冲突错误。我一直在围绕原型对象的初始化,评论事物无济于事。您能看到底部的Javscript出了什么问题吗?

<?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<div id="caitlinVendors">
<?php if ($_product->isSaleable() && count($_attributes)):?>
    <dl>
    <?php foreach($_attributes as $_attribute){ ?>
                <div id="<?php echo $_attribute->getLabel() ?>Box" class="attributeBox">
                    <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
                    <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
                        <div class="input-box">
                            <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
                                <option><?php echo $this->__('Choose an Option...') ?></option>
                              </select>
                          </div>
                    </dd>
                </div>

    <?php }?>
    <a href="#" id="vendorsButton" class="vendorsButtonOff">Show Vendors</a>
    <div class="clear"></div>

    </dl>
    </div>


    <script type="text/javascript">//Caitlin
    //dropdowns are initiated via configurable.js

    var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


    var $j= jQuery.noConflict();
        $j("#vendorsButton").on("click", function(event){ //vendor button click event
            event.preventDefault();
            $j('#vendorBox').css('visibility','show'); //set vendor box to visible

            if ($j("#vendorBox").is(":hidden")) {
                $j("#vendorBox").slideDown("fast");
            } else {
                $j("#vendorBox").hide();
            }
        });




    $j('select').change(function() { //on changing the attribute input
        if ($j(this).find('option:selected')[0].text=='Choose an Option...')//see if there is a value in the dropdown
        { 
            $j('#vendorsButton').removeClass().addClass('vendorsButtonOff'); //Gray out the button and disable
            console.log('i still work');
        }
        else
            $j('#vendorsButton').removeClass().addClass('vendorsButtonOff'); //Enable and make it gold
    });


    </script>
<?php endif;?>
有帮助吗?

解决方案

首先尝试评论jQuery代码,看看错误是否复制。如果确实如此,那与jQuery无关(显而易见的是)。
如果未出现错误,请尝试将 jQuery.noConflict() 末尾的声明 jquery.js 文件。在您打电话之前,在页面上的冲突有可能出现更高的冲突 noConflict.
而不是贬低变量 $j=jQuery.noConflict() 只是使用 jQuery 而不是“ $ j”。
例如:

var $j= jQuery.noConflict();
$j('#id').hide();

只是使用:

jQuery('#id').hide();

这总是对我有用的,没有任何冲突。
主题(一种):尝试将原型用于简单事物,例如隐藏和显示元素,设置样式值。无需将jQuery涉及您可以与原型一行的事情。

其他提示

我的URL有一个错误 # 在最后。可能是一个 <a href="#"> 那不是 preventDefault().

许可以下: CC-BY-SA归因
scroll top