$(document).on("click", '.gifyImage', function(event) {
var clickedImage = $(event.target);
if(clickedImage.data('state') === "animate") {
//set to still
clickedImage.data('state', "still");
// update state clickedImage.data('state', 'animate');
clickedImage.data('state', "animate");
} else {
//set to animate
clickedImage.data('state', "animate");
//update state to still
clickedImage.data('state', "still");
}
clickedImage.attr('src', clickedImage.data('still'));
console.log(event.target);
})
gifImage.data(state, 'animate');
^^^那是我打开开发工具时遇到的所谓错误
我为什么要编写此函数的背景知识。我有一项作业,要求我保持gif图像静止不动,并且单击gif时它将开始播放(动画),并且当我再次单击它时,它将回到静止。这段代码给我一个错误:“状态未定义” the error im getting
答案 0 :(得分:3)
在这一行
gifImage.data(state, 'animate');
将state
放入引号:
gifImage.data('state', 'animate');