Custom.js文件中的错误是什么?

时间:2012-08-11 20:11:16

标签: javascript jquery

我正在尝试将以下代码添加到其中:

$("#tabs").tabs("#tab-items section", {
  effect: 'fade',
  fadeOutSpeed: 0,
  fadeInSpeed: 400
});

$(".option-set").on("click", "a", function(e) {
    $(this).addClass('selected')
      .parent().siblings().find("a").removeClass('selected');
});

但无论我把它放在哪里,我都会收到错误并且随机的东西停止工作。这是我的整个custom.js文件,我是否对文件进行了不正确的编码?我不完全确定何时应该使用$(function(){命令,如果没有它就没关系。

/* --------------------------------------------------------------

INDEX:

[1] Search
[2] Popout Window
[3] Form Numbers
[4] Nav Bar
[5] Smooth Scroll
[6] Estimate Form

-------------------------------------------------------------- */

/* --------------------------------------------------------------

[1*] Search

-------------------------------------------------------------- */

document.getElementById('headerSearch').onsubmit = function() {
    window.location = "javascript:poptastic('http://www.google.com/search?q=site:northtownsremodeling.com ' + document.getElementById('headerInput').value);"
      return false;}

/* --------------------------------------------------------------

[2*] Popout Window

-------------------------------------------------------------- */

var newwindow; function poptastic(url){
  newwindow=window.open(url,'name', 'height=800,width=1020,scrollbars=yes');
    if (window.focus) {newwindow.focus()}}

/* --------------------------------------------------------------

[3*] Form Numbers

-------------------------------------------------------------- */

jQuery(function($){
    $("#menu-primary-number").mask("(999) 999-9999");
    $("#menu-zip").mask("99999");
});

/* --------------------------------------------------------------

[4*] Set Selected Menu Items & Hide

-------------------------------------------------------------- */
/*START FUNCTION*/
$(function() {

    $("#header-subnav ul").hide();
    $('.menu-option-set a[data-subid]').on('click', function(e) {
        e.preventDefault();
        var $s = $("#" + $(this).attr('data-subid'));                
        if($s.is(':hidden')) {
            $("#header-subnav").removeClass('hidden');
            $("#header-subnav ul").hide();
            $s.show();
        } else {
            $s.hide();
            $("#header-subnav").addClass('hidden');
        }
    });

    $('.menu-option-set a').click(function()
    {
        // if clicked item is selected then deselect it
        if ($(this).hasClass('selected'))
        {
            $(this).removeClass('selected');
        }

        // otherwise deselect all and select just this one
        else
        {
            $('.menu-option-set a').removeClass('selected');
            $(this).addClass('selected');
        }
    });

/* --------------------------------------------------------------

[5*] Smooth Scroll

-------------------------------------------------------------- */

    $('.navbar a, .scroll a, .smoothscroll a').bind('click',function(event){
        var $anchor = $(this);

        $('html, body').stop().animate({
            scrollTop: $($anchor.attr('href')).offset().top
        }, 850,'easeInOutExpo');
        /*
        if you don't want to use the easing effects:
        $('html, body').stop().animate({
            scrollTop: $($anchor.attr('href')).offset().top
        }, 1000);
        */
        event.preventDefault();
    });



/* --------------------------------------------------------------

[6*] Estimate Form

-------------------------------------------------------------- */

    // Setup any needed variables.
    var $form   = $('.estimate-form'),
        $loader = '<img src="/img/loader.gif" height="11" width="16" alt="Loading..." />';

    $form.append('<div id="response" class="hidden">');
    var $response = $('#response');

    // Do what we need to when form is submitted.
    $form.on('click', 'input[type=submit]', function(e){

        // Hide any previous response text and show loader
        $response.hide().html( $loader ).show();

        // Make AJAX request 
        $.post('/resource/script/estimate-send.php', $form.serialize(), function( data ) {

            // Show response message
            $response.html( data );

            // Scroll to bottom of the form to show respond message
            var bottomPosition = $form.offset().top + $form.outerHeight() - $(window).height();

            if( $(document).scrollTop() < bottomPosition )
                $('html, body').animate({ scrollTop : bottomPosition });

            // If form has been sent succesfully, clear it
            if( data.indexOf('success') !== -1 )
                $form.find('input:not(input[type="submit"], input[type="reset"]), textarea, select').val('').attr( 'checked', false );

        });

        // Cancel default action
        e.preventDefault();
    });

});/*END FUNCTION*/

谢谢你们! /加尔斯!

编辑:我输入时出现的错误是:

未捕获的TypeError:对象[object Object]没有方法'tabs'

1 个答案:

答案 0 :(得分:2)

您好像没有将JQueryUI.js添加到HTML文件中。