別のプロトタイプjQuery紛争の問題は私が思う
-
16-10-2019 - |
質問
製品ページの構成可能なオプションブロック内で作業しており、その下部にJavaScriptを挿入しています。問題はありませんでしたが、突然コンソールでエラーが発生しました。紛争エラーだと思います。私はプロトタイプオブジェクトの初期化を動き回り、物事に役に立たないことをコメントしてきました。下部にある私の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();
これは常に紛争なしで私のために働いていました。
オフトピック(一種):要素を隠したり表示したり、スタイルの値を設定するなど、単純なものにプロトタイプを使用してみてください。プロトタイプで1行でできることのためにjQueryを巻き込む必要はありません。
他のヒント
URLがあるときにこのエラーが発生します #
最後に。おそらくa <a href="#">
そうではありません preventDefault()
.
所属していません magento.stackexchange