属性和属性有什么区别? [英] What is the difference between attribute and property?

查看:136
本文介绍了属性和属性有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些似乎意味着同一件事.但是,在什么情况下,哪个术语更合适?

These seem to mean the same thing. But what term is more appropriate in what context?

推荐答案

在一般术语(以及正常的英语用法)中,这些术语含义相同.

In general terms (and in normal English usage) the terms mean the same thing.

在HTML/Javascript的特定上下文中,由于DOM元素的HTML表示具有属性(在XML中用于标记中包含的键/值对的术语),因此使术语混淆),但当表示为JavaScript对象时,这些属性将显示为对象 properties .

In the specific context of HTML / Javascript the terms get confused because the HTML representation of a DOM element has attributes (that being the term used in XML for the key/value pairs contained within a tag) but when represented as a JavaScript object those attributes appear as object properties.

为了进一步混淆,对属性的更改通常会更新属性.

To further confuse things, changes to the properties will typically update the attributes.

例如,更改element.href 属性将更新元素上的href 属性,这将反映在对element.getAttribute('href')的调用中

For example, changing the element.href property will update the href attribute on the element, and that'll be reflected in a call to element.getAttribute('href').

但是,如果您随后 read 该属性,即使 attribute 可能是相对URL,该属性也将被标准化为绝对URL!

However if you subsequently read that property, it will have been normalised to an absolute URL, even though the attribute might be a relative URL!

这篇关于属性和属性有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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