可以将自定义属性存储在HTML DOM中,如数据库记录吗? [英] Can I store custom attributes in HTML DOM like a database record?

查看:137
本文介绍了可以将自定义属性存储在HTML DOM中,如数据库记录吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用jQuery开发浏览器FF3和IE6 / 7时,在HTML标签上设置自定义属性时是否存在任何兼容性问题?

When developing for browsers FF3 and IE6/7 with jQuery, are there any compatibility issues when setting custom attributes on HTML tags?

首先,我知道jQuery的 data()函数,它本质上是我想要的,但数据不能存在于一个 clone()功能。当使用jQuery UI draggable / droppable插件时,这是一个问题,因为它在拖放期间克隆了DOM元素。为了这个问题的目的,我需要一个替代方案 data()

First, I'm aware of jQuery's data() function and it essentially does what I want, but the data doesn't survive a clone() function. This is an issue when using the jQuery UI draggable/droppable plugins because it clones DOM elements during a drag/drop. For the purpose of this question, I need an alternative to data().

拖放操作。我想要能够将数据注入到拖放操作期间移动的DOM元素中。为此,我可以构建HTML子元素来模拟数据库记录。快速实验表明,Firefox没有使用任何要存储数据字段的属性名称的问题。但是,HTML 4规范表示某些标签只能包含某些属性名称。使用非标准属性填充DOM会导致我提到的浏览器不兼容问题?

I want to persist data between drag/drop operations. I want to be able to inject data into the DOM element that is moved during a drag/drop operation. To do this, I can build HTML child elements to simulate a database record. Quick experimentation shows that Firefox has no issues utilizing any attribute names I want to store fields of data. However, the HTML 4 spec says that certain tags can only contain certain attribute names. Will populating the DOM with nonstandard attributes cause incompatibility issues with the browsers I've mentioned?

推荐答案

看看这个类似的问题我问了一会儿:我可以只是组成属性在我的HTML标签?

Take a look at this similar question I asked a while back: Can I just make up attributes on my HTML tags?

我个人并不喜欢将所有数据放入类属性的建议答案。感觉,只是...你知道吗根据我的经验,虽然你的页面如果你构成属性是无效的,我只是这样做。在4个主要浏览器中进行测试,如果它有效,谁在乎?

Personally, I don't really like the suggested answers of putting all your data into the class attribute. It feels, just... wrong you know? In my experience, though your page won't be valid if you make up attributes, I just do it anyway. Test it in the 4 major browsers and if it works, who cares?

我想到的最好的解决方案是无效的 / em>,但将在HTML5中,这样做很好。根据ms2ger在其他问题中的建议,用数据前缀您的自定义属性 -

The best solution which i can think of is one which isn't valid now, but will be in HTML5, so that's good. As suggested by ms2ger in that other question, prefix your custom attributes with data-

http://www.whatwg。 org / specs / web-apps / current-work / multipage / dom.html#embedding-custom-non-visible-data

这篇关于可以将自定义属性存储在HTML DOM中,如数据库记录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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