javascript - .live() 的行为与 .bind() 不同

标签 javascript jquery

问完这个问题后:jQuery die() does not work 。我发现 live() 的行为似乎不像 bind()

我有以下行:

$('.produit').die().live('change',function(){ // the rest
$('.produit').live('change',function(){ // that did not work either

然后我将其更改为:

$('.produit').unbind('change').bind('change',function(){ // the rest

两条线有什么区别。

在此示例中,.produit 被动态添加到页面中。绑定(bind)是在 prepend() 之后完成的。

我使用的是 jQuery 1.4.2 和 IE7。

最佳答案

如果您使用 IE,则实时和 change 事件会出现问题

搜索可以解决此问题的livequery插件。

尝试将事件更改为 Click 事件,您会发现它有效。

区别在于Bind适用于Already In Page元素,而live适用于also+Future元素。

关于javascript - .live() 的行为与 .bind() 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8038545/

相关文章:

javascript - Express.js 和 Bluebird - 处理 promise 链

Javascript 动态更改元数据/元标签

javascript - 将多维 json 数组中的一组属性列入白名单并删除其余属性

jquery - 正确的 jQuery 应用程序模块模式

javascript - 如何在url地址中使用参数#进行重定向,我使用laravel 5.8

javascript - 使用 jQuery 在 ajax 调用中仅发送数组中对象的少数属性

javascript - React useEffect 一次性获取 firestore 数据

javascript - 如何通过 index.html 在 Firebase 存储中显示图像

javascript - 如何通过ajax post发送值输入类型的文本?

javascript - Json - 日期未以正确的格式显示