开发者

Initialise call back function

开发者 https://www.devze.com 2023-02-04 09:59 出处:网络
I have this piece of jQuery which is using a call back on selection. new Shopify.OptionSelectors(\"product-variants\", {product: product, onVariantSelected: selectCallback}); // initialize multi sel

I have this piece of jQuery which is using a call back on selection.

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

however when I try to select using jQuery it doesn't initialise the callback

 开发者_运维百科$("#product-variants-option-0 option[value=" + selectedVal+"]").attr("selected","selected") ; 


Changing attribute in the code doesn't suppose to fire any callbacks, there are two ways to handle it. First after setting the attribute you should fire he callback yourself or you probably might need to use trigger function instead of trying to change attribute:

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

or even simulate a click:

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

精彩评论

暂无评论...
验证码 换一张
取 消