找不到具体答案。
如果我创建了一个jQuery函数,请说一个“ doMobile”,如果要,我希望它在其中使用一个函数,该怎么办?
这就是我想要做的:
$.fn.doMobile = function(somefunctioninside) {
if ( $('.mobile').is(':visible') )
somefunctioninside();
};
$('.menu').doMobile(function() {
$(this).css('background-color', 'red');
});
但是当我这样时,$(this)-$('。menu)不会变成红色。
试试这个
$.fn.doMobile = function (someFunction) {
someFunction.call(this);
};
$('.menu').doMobile(test);
function test() {
this.css('background-color', 'green');
alert("came");
}
通过this
参考。@Karl-AndréGagnon这样说
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句