jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 如何使用data()存储的数组设置和检索值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个数组,将其分配给div元素,push()一个值并在稍后阶段再次检索它.

有人能告诉我,我错过了什么……:

// set Array
// $(this) is the HTML-element which should get array assigned
var stack = [],stack.push('#'+$(this).find(':jqmData(role="page")').attr('id')),$(this).data( stack );

运用

console.log( $(this).data(stack) );

我正在取回整个HTML元素

console.log( $(this).data(stack[0] OR stack.length) );

不工作.

如何访问我(推测……)推入阵列的元素?

解决方法

您需要为数据命名.例如:

$("div").data("stack",[]); //This sets the data key "stack" to an empty array
$("div").data("stack").push(123); //This retrieves the array and pushes a number to the array
console.log($("div").data("stack")); //This prints the array

大佬总结

以上是大佬教程为你收集整理的jquery – 如何使用data()存储的数组设置和检索值全部内容,希望文章能够帮你解决jquery – 如何使用data()存储的数组设置和检索值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。