html & [removed] How to store data referring to html elements

前端 未结 8 1168
悲哀的现实
悲哀的现实 2020-12-31 15:29

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 p

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 15:52

    To answer the question of "how to get it into the document in the first place", I suggest a layout similar to this:

    • Some Username
    • Some Username

    This allows you to easily select a lot of info about your users:

    $('#users > li') // all user elements
    $('.someStatus') // all users of a particular status
    

    Then in your event handlers it's also easy to get the current status:

    $(this).attr('class') //get current status once you have a user element selected.
    

    Another alternative is to dump javascript to the page and simply have it use the jquery data functionality to store the data as soon as the page loads. You'd still need an id on the element in order to find the right one though.

提交回复
热议问题