gpt4 book ai didi

jQuery 的 setData/getData 事件应该能够覆盖 $.data() 的默认行为...但是如何覆盖呢?

转载 作者:行者123 更新时间:2023-12-01 06:07:33 25 4
gpt4 key购买 nike

查看有关 1.4.3 版本的官方博客文章:http://blog.jquery.com/2010/10/16/jquery-143-released/

我对这句话(在“事件”下)感到非常困惑:

jQuery has already had setData and getData events (which are broadcast whenever data is set or gotten through the .data() method) – overriding these methods makes it possible to override the default behavior for those features (namely you can return a different value or prevent a value from being set).

  1. “(...) 有 setData 和 getData 事件 (...) - 覆盖这些方法” - 哪些方法?!?

  2. “可以覆盖默认行为”——如何?!?我已经研究了源代码,但我想不出任何方法来“返回不同的值”或“阻止设置值”。

有谁比我更了解吗?

最佳答案

您可以使用 setDatagetData 事件订阅这些事件:

$(document.body).bind('setData', function(event, key, value) {
console.log(key + ': ' + value);
});

当调用以下命令时,这将记录“example: hello, world”:

$('a:first').data('example', 'hello, world');

除非我完全误解了代码的工作原理,否则无法更改默认操作,包括 e.preventDefault();。请参阅the relevant lines in data.js$.fn.data的源代码。

关于jQuery 的 setData/getData 事件应该能够覆盖 $.data() 的默认行为...但是如何覆盖呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4102534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com