开发者

Where to store the data for jquery?

I have gallery and a custom css drop-down menu to choose a category. If the user does not have javascript enabled, he should be able to click the a anchor without any problems. Otherwise, jquery & ajax are used. My problem is, how do I know the category selected? Storing it 开发者_StackOverflow中文版as an attribute isn't an option, because it doesn't validate, even though it's convenient. I use HTML5 doctype but I am not sure if I should use data, because I might need to validate it to xhtml again. Are there any other good options?


$(this).data('key', 'value'); 

would work in the context of an event handler assigned to an element where this refers to the element.

If you have to store it initially on page load, use data-attribute.


I would go with @meder's answer,
but if the page needs to load with the category, and you don't want to use data-attribute
then another option is to store the data at the class attribute, it can even be a json string and you can parse it to an object using the metadata plugin

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜