创建自己的 CSS 属性合法吗?
我正在为我的网站开发一个窗口应用程序。 现在,我将每个单独的窗口设置为网站正文中的 。 我通过在 body 元素末尾添加适当的代码来添加新窗口,并通过删除该 div 来删除它们。 (我使用 jQuery 作为底层 JavaScript 架构。)
我发现对于每个窗口,我希望能够存储一些不直接使用的值。 假设我最大化一个窗口,我想保存它的旧位置和大小,这样当我取消最大化它时,它会返回到它的旧位置,而不仅仅是随机的某个地方。 所以我真正的问题是,创建自定义 CSS 属性(完全知道浏览器会忽略它们)是否合法,其唯一目的是在每个 div 的基础上保存这样的信息? 或者这会是非法的吗?我应该考虑其他选择吗?
我当然熟悉将所有这些都保存在一个数组中的方法,这样系统就可以盲目地运行它,但这很可爱,而且很容易出现错误和问题,而且仍然有点棘手与. 一起工作。
谢谢
I'm working on a windowing application for a website of mine. Right now, I have each individual window set up as a in the body of the site. I add new windows by literally adding the appropriate code to the end of the body element, and delete them by removing that div. (I'm using jQuery for the underlying JavaScript architecture.)
I've found that for each window, I want to be able to store some values that aren't used directly. Say I maximize a window, I would want to save its old position and size so that when I un-maximize it, it returns to its old position and not just to somewhere random. So my real question here is, would it be legal to create custom CSS attributes (knowing full well that the browser would ignore them) with the sole purpose of keeping information like this on a per-div basis? Or would this be illegal, and should I look at another alternative?
I'm certainly familiar with methods of keeping all of this in an array so the system can run blind with it, but that's lovely and prone to errors and things, and it would still be a bit tricky to work with.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会使用 jQuery 的
data()
方法来存储临时数据。参考:
您还可以使此数据持久化通过将其存储在服务器端的 cookie 或会话中,并在页面加载时将其恢复到客户端。 这样,即使用户重新加载页面,窗口的位置和状态也将被保留。
I would use jQuery's
data()
method instead for storing temp data.References:
You can also make this data persistent by storing it in cookies or in session at server side and restore it on the client when page loads. This way, window’s position and state will be kept even if user reloads the page.
jQuery 有一个鲜为人知的功能,称为
data
。 有了它,你可以这样做:如果你不喜欢这个(虽然我发现它很方便),那么拥有自定义属性当然没有错,尽管这会使其成为无效代码。
jQuery has a little-known feature for this called
data
. With it, you can do this:If you don't like this (although I find it quite handy) it is certainly not wrong to have custom attributes, although this will make it invalid code.