javascript - jQuery问题:"TypeError: r.easing[this.easing] is not a function"
PHP中文网
PHP中文网 2017-04-11 11:19:07
0
2
1208

我在使用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中文网

认证0级讲师

모든 응답(2)
PHPzhong

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

迷茫
<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>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿