开发者

Store values in html

I have a bunch of elements (divs) and they represent items. I can delete them by clicking a link and its done through ajax. I had the divs store the value in id however it appears that even though it does work the standard says id names must start with a letter. So i could start it开发者_如何学运维 with a letter and remove it when i use ajax or i can store the value another way.

What are ways i can store values in html? I don't think inputs are legal outside of forms but i am rethinking what are good ways to store values.


Best way is to use the new HTML 5 spec to store data in the data-[name] in the div elements

ie

<div data-yourfield="value">
  Text
</div>

Then using jQuery find the divs with the selector (reference http://api.jquery.com/category/selectors/)

div[data-yourField=""]


You can store it as text inside the div if you like. You also can use inputs, just add the form tag around everything. Just because it's a form doesn't mean it has to "submit". Inputs or textboxes would probably be the best way to store them actually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜