我已经添加了一个使用jQuery的点击事件来改变我的CSS。点击工作和CSS更改,但随后jQuery继续运行并最终将CSS恢复为原始状态。jQuery恢复CSS回到原来的状态
jQuery代码:
$('.myClass').click(function(){
$('.myClass').css({"visibility":"hidden"});
});
CSS代码:
.myClass {
height: 10px;
width: 10px;
background: red;
visibility:visible;
}
就像我说的,点击作品和元素获取隐藏。但是,当jQuery完成代码运行时,它会立即恢复。使用谷歌浏览器的调试工具,我发现这是jQuery代码中的一个要点,它将CSS恢复为让元素可见。
jQuery的代码(行4116):
if (!(eventHandle = elemData.handle)) {
eventHandle = elemData.handle = function(e) {
// Discard the second event of a jQuery.event.trigger() and
// when an event is called after a page has unloaded
return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
line 4116 jQuery.event.dispatch.apply(elem, arguments) : undefined;
};
}
我想我不明白什么是与这个jQuery代码发生,为什么我的CSS得到恢复回来?任何帮助理解都非常感谢。
你可以发布你所有的jQuery和你的html吗?我已经运行这个代码,它适用于我。 – Brino