我有一组数据,我将使用PHP回显到一个页面,并且我希望JQuery能够解析它。但是,我不希望用户可以看到数据。我有,例如:如何在页面上存储数据并通过JQuery检索?
<div id="data-1">
<span id="width">5</span>
<span id="height">10</span>
<span id="depth">15</span>
</div>
<div id="data-2">
<span id="width">10</span>
<span id="height">20</span>
<span id="depth">30</span>
</div>
我想知道如果我应该存储跨度这样的数据,然后在JQuery中,隐藏它们onload事件和后来得到的跨度值与数据玩:
$(document).ready(function() {
$("#width, #height, #depth").hide();
$("#data-*").click(function() {
var width = $("#width", $(this)).text();
var height = $("#height", $(this)).text();
var depth = $("#depth", $(this)).text();
});
});
这是在页面上存储数据的最有效方式吗?我是否应该使用隐藏的输入,还是有其他方法来执行此操作?
我喜欢这个主意!感谢您的帮助 - 也感谢所有其他人。 – ash 2009-05-23 05:51:34
如果您想将此JSON与特定的HTML元素相结合,请查看下面的答案:http://stackoverflow.com/questions/899327/how-to-store-data-on-a-page-and-检索它通过jquery/4246901#4246901 – Andreas 2010-11-22 15:20:13