suchen

Heim  >  Fragen und Antworten  >  Hauptteil

javascript - jQuery问题:"TypeError: r.easing[this.easing] is not a function"

我在使用jQuery的toggle函数的时候出现了这样一个问题
这是我的代码:

$(document).ready(function() {
    $("#button1").toggle(
    function() {
        alert(1);
    }, 
    function() {
        alert(2);
    }, 
    function(){
        alert(3);
    });
});

然后这个是异常:

jQuery.Deferred exception: r.easing[this.easing] is not a function TypeError: r.easing[this.easing] is not a function
    at Xa.run (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:3:23582)
    at i (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:3:26835)
    at Function.r.fx.timer (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:3:30432)
    at gb (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:3:27668)
    at HTMLButtonElement.g (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:3:28879)
    at Function.dequeue (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:3:2716)
    at HTMLButtonElement.<anonymous> (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:3:3151)
    at Function.each (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:2:2813)
    at r.each (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:2:1003)
    at r.queue (http://localhost:8080/JSTest/JavaScript/jquery-3.0.0.min.js:3:3056)

我试过stackoverflow上的方法,引入了什么jquery-ui,可是引入了之后不仅还是不行,jquery-ui还报错了,这个怎么解决啊,我是照着书上敲的啊。

PHP中文网PHP中文网2776 Tage vor1176

Antworte allen(2)Ich werde antworten

  • PHPz

    PHPz2017-04-11 11:21:07

    你用的jq版本是3.0.0, 而toggle函数自jq 1.9开始就已经被移除了, 所以你调用toggle方法的时候, 会报方法不存在

    Antwort
    0
  • 迷茫

    迷茫2017-04-11 11:21:07

    <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("button").toggle(
        function() {
            alert(1);
        }, 
        function() {
            alert(2);
        }, 
        function(){
            alert(3);
        }
      );
    });
    </script>
    </head>
    <body>
    <button>请点击这里,来切换不同的背景颜色</button>
    </body>
    </html>
    

    Antwort
    0
  • StornierenAntwort