- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用它们很长一段时间了,但大多数时候,我更喜欢较短的,但是,我只是想真正深入了解本质细节。我可能一直在创建有错误的代码,并且我不想在网络上贡献和传播懒惰完成的代码。
所以,告诉我:
What are the significant advantages/disadvantages among them, or is it just like ice cream, different flavors but same "feel-good" effect?
鼓励每个人就此事发表专家意见。
提前非常感谢。
最佳答案
bind()
在 1.0 中添加,live()
在 1.3 中添加,delegate()
在 1.4.2 中添加,on 1.7 中的 ()
。
从 1.7 开始,on()
是首选使用方式,而 live()
已被弃用,根本不推荐使用。如果您使用的是 1.3,请使用 bind()
而不是 live()
,并且从 1.4.2 开始,请使用 delegate()
而不是 live()
以及从 1.7 开始使用 on()
而不是其他任何一个。
关于$("selector").click
。取自 click()
documentation :
In the first two variations, this method is a shortcut for .bind("click", handler), as well as for .on("click", handler) as of jQuery 1.7. In the third variation, when .click() is called without arguments, it is a shortcut for .trigger("click").
为什么使用 on() 而不是其他的?on()
是最新添加的内容,在 1.7 版中加入了 jQuery 库。 on()
有多个方法签名,使其能够提供与先前版本相同的结果,但经过改进和优化。引用documentation :
As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers.
基本上不再需要使用bind()
或delegate()
。当然它会起作用,并且使用这些方法应该不会有什么坏处,但我总是假设最新的添加内容针对以前版本的任何缺点进行了优化和改进(除非文档另有说明,就像 live()
)。
基于此,我建议改用 on()
。
不推荐使用live()
的原因更多是因为它的缺点。引用live()
documentation 。
Use of the .live() method is no longer recommended since later versions of jQuery offer better methods that do not have its drawbacks. In particular, the following issues arise with the use of .live():
- jQuery attempts to retrieve the elements specified by the selector before calling the .live() method, which may be time-consuming on large documents.
- Chaining methods is not supported. For example, $("a").find(".offsite, .external").live( ... ); is not valid and does not work as expected.
- Since all .live() events are attached at the document element, events take the longest and slowest possible path before they are handled.
- On mobile iOS (iPhone, iPad and iPod Touch) the click event does not bubble to the document body for most elements and cannot be used with .live() without applying one of the following workarounds:
- Use natively clickable elements such as a or button, as both of these do bubble to document.
- Use .on() or .delegate() attached to an element below the level of document.body, since mobile iOS does bubble within the body.
- Apply the CSS style cursor:pointer to the element that needs to bubble clicks (or a parent including document.documentElement). Note however, this will disable copy\paste on the element and cause it to be highlighted when touched.
- Calling event.stopPropagation() in the event handler is ineffective in stopping event handlers attached lower in the document; the event has already propagated to document.
- The .live() method interacts with other event methods in ways that can be surprising, e.g., $(document).unbind("click") removes all click handlers attached by any call to .live()!
不过,文档中还有更多好东西。
关于jquery - $(sel).bind ("click"、 $(sel).click(、 $(sel).live ("click"、 $(sel).on ("click"之间有什么显着差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11148019/
我已经使用它们很长一段时间了,但大多数时候,我更喜欢较短的,但是,我只是想真正深入了解本质细节。我可能一直在创建有错误的代码,并且我不想在网络上贡献和传播懒惰完成的代码。 所以,告诉我: What a
我似乎无法正常工作,我想检查是否选择了 AM-1 路线,然后是否也选择了值“1vlucht”并相应地更改 innerHTML。这可能吗?我也尝试过 && 但没有运气。 我什至不确定你是否可以为 1 个
您建议如何处理此错误? Actor 阵容是否必要第一名? - (NSMethodSignature*)methodSignatureForSelector:(SEL)selector { retu
从 objc 源代码我们可以看到 SEL 被定义为 typedef struct objc_selector *SEL; 我用 idaq 反汇编了我的 dylib ,我确实调用了 _MSHookMes
我有以下 XML 我确实从属性中获得了正确的值,但我想用新行将它们分开以进行进一步处理。 使用命令时 xmlstarlet sel -t -v "count(process/@id" "exa
我想将选择器添加到 NSMutableArray。但由于它们是不透明类型并且没有对象,所以这是行不通的,对吧?有我可以使用的包装对象吗?还是我必须创建自己的? 最佳答案 您可以将其包装在 NSValu
我正在尝试让另一个对象调用选择器。我试图通过定义选择器属性从另一个类定义这个选择器。它似乎没有像我预期的那样工作。 组合框.h @property (nonatomic) SEL onComboSel
当你只有一个 SEL 对象时,似乎应该有一种简单的方法来调用带有一些参数的选择器。我似乎找不到正确的语法。 -(MyClass*) init: (SEL)sel owner:(NSObject*) p
命令 $ xmlstarlet sel -t -c "/collection/record" file.xml 似乎在应用给定的 Xpath 表达式之前将整个文件加载到内存中。这不适用于大型 XML
我刚刚在在线教程中发现了以下内容。它显示 001 作为分配选择器的方法,但是我无法让它工作。我是否正确地认为 001 不对,002 是正确的方法,还是我对 001 做错了什么? // 001 SEL
带有选择标签的 HTML: ` 在 JavaScript 部分,我试图在选择下拉列表中添加选项,在循环中创建它们,将数组值分配给选项: var sel = document.getElementByI
我的 PHP 代码有问题。在前一页中,用户输入他们的用户名。现在,当他们提交表单时,用户名会发布并回显在当前页面上。 例如,如果教师输入“j.lu”作为用户名,它会在当前页面上发布“j.lu”。 但我
我只是好奇是否有办法动态提取 SEL 名称? 不确定如何提取 SEL,因为它是一个 typedef 结构。 谢谢。 最佳答案 请详细说明。但是,我相信您正在尝试将 SEL 转换为 NSString。如
我有一个来自字符串的 SEL。我可以使用“method_copyArgumentType”,这是一个运行时函数来获取每个参数的类型,就像这样 char *arguType = method_copyA
当我将一个选择器传递给我的方法时,我是否应该只保存它: -(void) setCallBack:(SEL) selectorToCall { self->mSelectorToCall = s
我最近阅读了由受人尊敬的 Bryan Oakley( Tkinter adding line number to text widget ) 撰写的答案,他在其中展示了有关解决问题的示例代码。 当我尝
我正在设置一个表格,格式如下。请原谅愚蠢的示例数据。所有这些实际上都是用 json 加载的,但输出如下所示: It was the best of times, it was the worst o
我有一个 appDelegate,它初始化了一个名为 LocationService 的类的实例。 我只想通过 init 传递给这个实例这个类将运行的方法。 我得到了这个异常(exception):
Perl-Selenium 还提供了 Test::More 的标准方法,例如 ok()、like()、is() 等,也作为对象方法,例如$sel->like()。 ($sel 是 selenium p
例如,我想跟踪发送到我的 canPeformAction 的操作,但它们数量太多,无法在调试器中通过“悬停”在每次出现时显示。因此,我想在我的测试周期后跟踪日志并检查它。 - (BOOL)canPer
我是一名优秀的程序员,十分优秀!