html& javascript:如何存储引用html元素的数据 [英] html & javascript: How to store data referring to html elements

查看:74
本文介绍了html& javascript:如何存储引用html元素的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究使用ajax与服务器通信的Web应用程序。
我的具体情况如下:

我在html页面列出了一个用户列表。在这些用户中,我可以执行以下操作:更改帐户的状态或从帐户中删除他们。



在页面中存储信息的最佳做法是什么关于以下内容:


  • 用户标识

  • 用户的当前状态



PS:我正在使用jQuery。

解决方案

有jQuery的数据函数
$ b $ $ $ $''''。data('userid',uid); //设置userid的值
uid = $('li')。data('userid'); //检索userid的值

官方文档: http://docs.jquery.com/Data


I'm working on a web application that uses ajax to communicate to the server. My specific situation is the following:

I have a list of users lined out in the html page. On each of these users i can do the following: change their 'status' or 'remove' them from the account.

What's a good practice for storing information in the page about the following:

  • the user id
  • the current status of the user

P.S.: I'm using jQuery.

解决方案

There is jQuery's data function

$('li').data('userid',uid); // sets the value of userid
uid = $('li').data('userid'); // retrieves the value of userid

official documentation: http://docs.jquery.com/Data

这篇关于html& javascript:如何存储引用html元素的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆