绑定“文档就绪”和“窗口滚动”

时间:2018-02-02 13:47:36

标签: javascript jquery events

这样我可以将一些事件绑定到“窗口加载”和“窗口滚动”:

$(window).bind('load scroll', function() {
    // ...
});

但是有办法绑定“文件就绪”和“窗口滚动”吗?

$(document).ready(function() {
    // ...
});

$(window).on('scroll', function() {
    // ...
}

// How to bind them together?

1 个答案:

答案 0 :(得分:1)

没有什么可以说你必须在调用jQuery时直接定义处理函数 - 你可以很容易地单独定义它并重用它。

{% for user in users %}
    <td>user.username</td>
    <td>user.server_limit</td>
    <td>...</td>
    <td>user.server_slot_count</td>
{% endfor %}

jQuery为你的第一个例子做了完全相同的事情(或多或少) - they just split the string on whitespace and then run the event registration code once for each

相关问题