使用 html 隐藏字段存储临时数据
我正在使用 javascript flot 库绘制图表。悬停或单击时我需要显示更多信息。为此,我需要更多信息。但 flot 只会给我点击点的 ( x, y ) 坐标。
我可以在 html 隐藏字段中存储所需的信息吗?可以/不好吗?或者我应该使用cookies?进行额外的 ajax 调用来获取信息怎么样?
谢谢
I'm plotting a graph using javascript flot library. When hovering or clicking i need to show more information. To do this, i'll need some more info. But flot will give me only the ( x, y ) co-ordinates of the clicked point.
Can I store the info needed in html hidden fields ? Is it OK/Bad? Or should I use cookies? What about making extra ajax calls to fetch info ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行 JavaScript 变量或隐藏字段。使用隐藏字段的主要好处是,如果您最终提交表单,则数据已经就位。
You can do either JavaScript variables or hidden fields. The main benefit to using hidden fields would be if you end up submitting a form the data would already be in place.
我会在您的页面中使用一些 Javascript,因为(我假设)您将有一个 Javascript 事件处理程序向用户提供信息。比如:
我当然不会使用 cookie 和隐藏字段,虽然它们可以工作,但会占用更多字符(更多的字符传输到浏览器),并且 Javascript 需要更多工作才能从 DOM 中提取数据。
如果您的数据量太大,导致页面太大(加载时间太长),那么您需要通过 Ajax 加载数据。
I would use some Javascript in your page, given that (I assume) you'll have a Javascript event handler providing the information to the user. Something like:
I certainly wouldn't use cookies, and hidden fields, while they would work, would take more characters (more to transfer to the browser) and take more work for Javascript to extract the data from the DOM.
If you have so much data that your page size is too big (load time too long), then you would need to load the data via Ajax.