gpt4 book ai didi

jQuery.data() : possible to increment (++ or --)?

转载 作者:行者123 更新时间:2023-12-03 21:45:31 24 4
gpt4 key购买 nike

在 jQuery 中增加值的最佳方法是什么 .data()目的?

最佳答案

这看起来有点奇怪,但根据文档 .data()将所有数据字段作为对象返回,因此您可以直接更改其值:

$('#id').data('counter', 0);

两个选项都有效:

$('#id').data().counter++;
$('#id').data()['counter'] += 5;

检索数据返回预期值:

alert($('#id').data('counter')); // 6

关于jQuery.data() : possible to increment (++ or --)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2688837/

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