且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在jQuery中声明和使用函数

更新时间:2023-11-09 11:34:16

这可能是一个错字,但您在jQuery选择器之前缺少 $ ,并且需要确保DOM在运行此代码之前已准备就绪:

This may be a typo, but you're missing the $ before the jQuery selector, and you need to be sure the DOM is ready before running this code:

$(function() {
    $("#first_link").click(function() {
         adjust_menu();
    });
});

执行 $(function(){...}); jQuery的 .ready()方法,可确保在代码运行之前DOM已准备就绪.如果 first_link 尚不存在,则选择该选项将无效.:o)

Doing $(function() { ... }); is a shortcut for jQuery's .ready() method which makes sure the DOM is ready before your code runs. Selecting first_link does no good if it doesn't exist yet. :o)