jQuery-只做一次 [英] jQuery - Do only once

查看:109
本文介绍了jQuery-只做一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个元素是否具有.active类,如果它确实添加了:margin-top:4px;

I want to check if an element has the class .active, if it does add: margin-top: 4px;

但是我只希望这种情况一次一次,在页面加载时,一旦检测到该类,我就不想再次检测到它并添加CSS样式.

However I only want this to occur once, when the page loads, once the class has been detected I don't want to detect it again and add the CSS style.

当某些元素悬停在该类上时,将应用此类.

This class is applied when certain elements are hovered over.

在jQuery中这可能吗?

Is this possible in jQuery?

推荐答案

查看一个事件.记录的示例:

Check out the one event. Documented example:

$('#foo').one('click', function() {
  alert('This will be displayed only once.');
});

这篇关于jQuery-只做一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆