2011-01-10 99 views
0

我有這段jQuery正在使用回調選擇。初始化回調函數

new Shopify.OptionSelectors("product-variants", {product: product, onVariantSelected: selectCallback}); // initialize multi selector for product 

但是當我嘗試使用jQuery選擇不初始化回調

$("#product-variants-option-0 option[value=" + selectedVal+"]").attr("selected","selected") ; 

回答

2

更改代碼中的屬性不設火任何回調,有兩種方法來處理它。設置該屬性後,首先你應該解僱他自己的回調或者你可能可能需要使用的,而不是試圖改變屬性觸發功能:

$("radio-button-selector").trigger("select"); 

,甚至模擬點擊:

$("radio-button-selector").trigger("click");