Jon*_*man 1 javascript jquery function jquery-selectors
myFunc()绑定到文档滚动,因此它将被调用很多.我想将HTML选择存储在var中并将它们传递给函数.当我在下面运行我的示例时,我得到控制台错误Unable to get value of the property 'css': object is null or undefined.
var a1 = $('#a1');
var a2 = $('#a2');
$(document).bind("scroll", function() {
setTimeout(myFunc, 1000, a1, a2);
}
function myFunc(a1, a2) {
a1.css('color', 'blue');
a2.css('font-weight', 'bold');
}
Run Code Online (Sandbox Code Playgroud)
如何将存储在变量中的多个jQuery选择器传递给函数?
$(document).bind("scroll", function() {
setTimeout(function() {
myFunc(a1, a2);
},1000);
}); // close );
function myFunc(a1, a2) {
a1.css('color', 'blue');
a2.css('font-weight', 'bold');
}
Run Code Online (Sandbox Code Playgroud)