1

第一个功能是

    $(function() {
        var pull        = $('#pull');
            menu        = $('.mnav ul');
            menuHeight  = menu.height();

        $(pull).on('click', function(e) {
            e.preventDefault();
            menu.slideToggle();
        });

        $(window).resize(function(){
            var w = $(window).width();
            if(w > 320 && menu.is(':hidden')) {
                menu.removeAttr('style');
            }
        });
    });

第二个功能是

$(document).ready(function() {
    $("#id1").click(function(){$("#id1").hide();$("#std_show").slideDown("slow");});
    $('#submit').click(function() {
        var text = escape($.trim($('textarea#form_text').val()));
        var code = escape($.trim($('input#form_code').val()));
        $('div#form_text_info').html('');
        $('div#form_code_info').html('');
        $('div#std_form_info').html('');
        var save = true;
        /*somthing*/
    });
});

两个功能没有一起运行?如果名称问题给出解决方案,因为我是JQ的初学者

4

2 回答 2

0

Both $(function() { and $(document).ready(function() { are the same. The first is merely a shorthand form of the second.

Both the function do nothing on their own except they hook click events on some html elements.

These are fired when the document is ready (the browser has created the DOM)

于 2013-08-20T05:00:23.587 回答
0

使用 jQuery 编写脚本时要遵循的重要标准之一是对页面仅使用一个 DOCUMENT 'Ready' 函数。

您可以使用 $(document).ready(function(){}) 或 $(function(){})。

后者是@UmairP 提到的前者的简写格式。您的代码没有问题。只需将准备好的功能合并为一个,然后重试。

快乐的脚本!

于 2013-08-20T05:43:30.283 回答