【问题标题】:Why do I get this JQuery error: $(".left_hand_icon").button is not a function为什么我会收到此 JQuery 错误:$(".left_hand_icon").button is not a function
【发布时间】:2013-07-12 19:09:53
【问题描述】:

这是我的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>

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

【问题讨论】:

    标签: javascript jquery function error-handling


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢@musa!我不想使用按钮,而是想为左右选项使用图像。如何调整脚本?
    • 一张图片仍然可以作为按钮使用,按钮就是功能,需要包含widget js
    • 我是 JS 新手,所以我不确定,这是不是正确的:
    • @KPO 这是一个 css 文件,而不是在部分中包含 jQuery ui,而是包含整个内容。 &lt;script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"&gt;&lt;/script&gt;
    猜你喜欢
    • 1970-01-01
    • 2020-09-13
    • 2022-06-22
    • 2018-10-28
    • 2010-10-30
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 2021-11-20
    相关资源
    最近更新 更多