为什么我得到这个JQuery错误:$(“。left_hand_icon”)。button不是一个函数

时间:2013-07-15 01:16:28

标签: javascript jquery function error-handling

这是我的jS代码:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.effects.core.js"></script>
    <script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.effects.slide.js"></script>

    <script src="js/mr_lp_minimizr.js"></script>
    <script>
$(document).ready(function(){

if(!Modernizr.input.placeholder){

    $('[placeholder]').focus(function() {
      var input = $(this);
      if (input.val() == input.attr('placeholder')) {
        input.val('');
        input.removeClass('placeholder');
      }
    }).blur(function() {
      var input = $(this);
      if (input.val() == '' || input.val() == input.attr('placeholder')) {
        input.addClass('placeholder');
        input.val(input.attr('placeholder'));
      }
    }).blur();
    $('[placeholder]').parents('form').submit(function() {
      $(this).find('[placeholder]').each(function() {
        var input = $(this);
        if (input.val() == input.attr('placeholder')) {
          input.val('');
        }
      })
    });

}

});
</script>
<script type="text/javascript">
jQuery.fn.extend({
  slideRightShow: function(speed) {
    return this.each(function() {
        $(this).show('slide', {direction: 'right'}, +speed || 1000);
    });
  },
  slideLeftHide: function(speed) {
    return this.each(function() {
      $(this).hide('slide', {direction: 'left'}, +speed || 1000);
    });
  },
  slideRightHide: function(speed) {
    return this.each(function() {
      $(this).hide('slide', {direction: 'right'}, +speed || 1000);
    });
  },
  slideLeftShow: function(speed) {
    return this.each(function() {
      $(this).show('slide', {direction: 'left'}, +speed || 1000);
    });
  }
});


$(document).ready(function () {
    $("#slides :first-child").addClass("currentSlide");
    $("#slides :not(:first-child)").hide();

    $(".left_hand_icon").button().click(function () { //This is the line where issue is
        currentSlide = $("#slides .currentSlide");

        if(currentSlide.prev().prev().size() < 1) {
            // The incoming slide is the first - disable Left button
            $(".left_hand_icon").button("disable");
        }

        currentSlide.prev().addClass("currentSlide");
        currentSlide.removeClass("currentSlide");

        currentSlide.prev().slideLeftShow();
        currentSlide.slideRightHide();

        $(".right_hand_icon").button("enable");
    }).button("disable");

    $(".right_hand_icon").button().click(function () {
        currentSlide = $("#slides .currentSlide");

        if(currentSlide.next().next().size() < 1) {
            // The incoming slide is the last - disable Right button
            $(".right_hand_icon").button("disable");
        }

        currentSlide.next().addClass("currentSlide");
        currentSlide.removeClass("currentSlide");

        currentSlide.next().slideRightShow();
        currentSlide.slideLeftHide();

        $(".left_hand_icon").button("enable");
    });
});
</script>

我将此评论添加到错误显示的行://这是问题所在的行

1 个答案:

答案 0 :(得分:4)

你还没有包含jQuery ui小部件。按钮就在哪里。

http://api.jqueryui.com/category/widgets/