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

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

问题描述

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

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

首先,我知道jQuery的数据()的功能,它主要是我想要做什么,但数据并没有生存克隆()功能。使用jQuery UI可拖动/投掷的插件时,因为它克隆一个拖/放过程中DOM元素,这是一个问题。对于这个问题的目的,我需要数据()

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?

推荐答案

看看这个类似的问题,我问了一段时间后:<一href=\"http://stackoverflow.com/questions/427262/can-i-just-make-up-attributes-on-my-html-tags\">http://stackoverflow.com/questions/427262/can-i-just-make-up-attributes-on-my-html-tags

Take a look at this similar question I asked a while back: http://stackoverflow.com/questions/427262/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?

这是我能想到的最好的办法是其中之一是无效的现在的,但会在HTML5中,所以这是很好的。正如在其他问题建议的ms2ger,preFIX您的自定义属性与数据 -

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-

<一个href=\"http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#embedding-custom-non-visible-data\">http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#embedding-custom-non-visible-data

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

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