Creating a reusable jQuery function

前端 未结 2 375
广开言路
广开言路 2021-01-24 14:56

Instead of re-writing a massive block of code each time, I\'m trying to incorporate functions into my work but I\'m having trouble making it work.

Basically, I\'ve got a

2条回答
  •  时光取名叫无心
    2021-01-24 15:11

    Pass in the themeName as an argument of the switchPreview function.

    -Change the first line of the function to:

    jQuery.fn.switchPreview = function (themeName) {
    

    -For each of the three times you are calling the function, make sure you are passing in the argument, i.e:

    $('.liveDemoFrame').switchPreview(themeName);
    

提交回复
热议问题