myFunc() 绑定(bind)到文档滚动,所以它会被调用很多。我想将 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');
}
如何将存储在变量中的多个 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');
}
关于javascript - 将多个 jQuery 元素选择器传递给一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12463282/