uncaught typeerror $(...)。swipe不是一个函数

时间:2015-08-02 11:04:56

标签: javascript jquery blogger

我试图在博客中制作一个可滑动的菜单,这是我的代码:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="https://www.googledrive.com/host/0B2Iusn9ixPQ2cFFldHoweXRsWms"></script>


<script type="text/javascript">
      $(window).load(function(){
        $("[data-toggle]").click(function() {
          var toggle_el = $(this).data("toggle");
          $(toggle_el).toggleClass("open-sidebar");
        });
         $(".swipe-area").swipe({
              swipeStatus:function(event, phase, direction, distance, duration, fingers)
                  {
                      if (phase=="move" &amp;&amp; direction =="right") {
                           $(".container").addClass("open-sidebar");
                           return false;
                      }
                      if (phase=="move" &amp;&amp; direction =="left") {
                           $(".container").removeClass("open-sidebar");
                           return false;
                      }
                  }
          }); 
      });

    </script>

并且我在“$(”。swipe-area“)中收到此错误.swipe({”:uncaught typeerror $(...)。swipe不是函数

PLease帮助, 感谢

3 个答案:

答案 0 :(得分:3)

试试这个

<html>
<head>

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate","#pageone",function(){
  $("p").on("swipe",function(){
    $(this).hide();
  });                       
});
</script>
</head>
<body>

<div data-role="page" id="pageone">
  <div data-role="main" class="ui-content">
    <p>If you swipe me, I will disappear.</p>
    <p>Swipe me away!</p>
    <p>Swipe me too!</p>
  </div>
</div> 

</body>
</html>

更新 - 意外的令牌

您的代码中的语法错误位于下一行

swipeStatus:function(event, phase, direction, distance, duration, fingers)

正确的语法 - 通过以下方式,您可以定义 swipeStatus 一个函数

var swipeStatus  = function(event, phase, direction, distance, duration, fingers)

答案 1 :(得分:0)

试试这个......

<script>
$(document).on("pagecreate","#pageone",function(){
  $("p").on("swipe",function(){
    $(this).hide();
  });                       
});
</script>`enter code here`

答案 2 :(得分:0)

  

回答:

首先加载所有jquery依赖项,然后加载touchSwipe库