HTML - 属性与属性 [英] HTML - attributes vs properties

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

问题描述

id HTML属性或属性



我应该如何做 $ ('#selector')。attr('id'); $('#selector')。prop('id');



我读过很多文章,但仍然感到困惑。

有人可以向我解释什么是差异属性和属性之间HTML / JS中的属性使用的语言非常简单?

解决方案

属性由HTML定义。属性由DOM定义。

有些HTML属性映射到属性上有1:1。 id 就是这样一个例子。



有些不会(例如属性指定了输入的初始值,但是属性指定了当前值。)


Is id an attribute or property of HTML?

should I do $('#selector').attr('id'); or $('#selector').prop('id');

I've read many articles and am still confused.

Could someone please explain to me what the differences between attributes & properties in HTML/JS are in very simple language?

解决方案

Attributes are defined by HTML. Properties are defined by DOM.

Some HTML attributes have 1:1 mapping onto properties. id is one example of such.

Some do not (e.g. the value attribute specifies the initial value of an input, but the value property specifies the current value).

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

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