【发布时间】:2017-07-03 17:31:10
【问题描述】:
$('#element').toggle(function(){
$(this).addClass('one');
},
function(){
$(this).removeClass('one').addClass('two');
},
function(){
$(this).removeClass('two').addClass('three');
});
#element{
width: 150px;
height: 150px;
border: 1px solid #000;
}
.one{
background: orange;
}
.two{
background: blue;
}
.three{
background: red;
}
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<div id="element"></div>
嗨,我正在尝试基于对同一 ID 的三次点击来开发 UI,这是我正在尝试的代码。但是当我渲染它时,我得到了错误
`Uncaught TypeError: r.easing[this.easing] is not a function
at init.run (jquery-3.1.1.min.js:3)
at i (jquery-3.1.1.min.js:3)
at Function.r.fx.timer (jquery-3.1.1.min.js:3)
at hb (jquery-3.1.1.min.js:3)
at HTMLDivElement.g (jquery-3.1.1.min.js:3)
at Function.dequeue (jquery-3.1.1.min.js:3)
at HTMLDivElement.<anonymous> (jquery-3.1.1.min.js:3)
at Function.each (jquery-3.1.1.min.js:2)
at r.fn.init.each (jquery-3.1.1.min.js:2)
at r.fn.init.queue (jquery-3.1.1.min.js:3)`
谁能帮我解决它。我用谷歌搜索,但没有找到解决方案。
谢谢。
CSKADMIN
【问题讨论】:
-
.toggle()不是这样工作的 -
你为什么要把 3 个函数放到
.toggle()里面没有任何意义...