Skip to content

HTML attribute 和 DOM property #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
justjavac opened this issue Nov 2, 2017 · 7 comments
Open

HTML attribute 和 DOM property #15

justjavac opened this issue Nov 2, 2017 · 7 comments

Comments

@justjavac
Copy link
Owner

justjavac commented Nov 2, 2017

文章:HTML attribute 和 DOM property

@justjavac
Copy link
Owner Author

2年了,终于填坑了

@zhangenming
Copy link

感谢.
另外与视图的关系呢
比如input 的value值 页面渲染结果
始终会与attribute 保持一致吗
之前我试过 三者好像关系不是那么简单

@justjavac
Copy link
Owner Author

始终会与 attribute 保持一致setAttribute 这个 api 操作的就是 attribute。如果第二个参数传 null,则会变成 "null"

@xusanduo08
Copy link

image
hi,你好,视图貌似并不是和attribute一直保持一致的啊。当在js中修改input的value属性值的时候,视图是跟着修改的啊。这个该怎么解释呢

@justjavac
Copy link
Owner Author

@xusanduo08 可能我说的不是很清楚。视图(HTML)总是和 attribute 保持一致,这里的视图指的是 HTML,而非用户看到的渲染结果。

@xusanduo08
Copy link

@justjavac 明白了,感谢!

@justjavac
Copy link
Owner Author

@xusanduo08 关于 value 的规范: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-value

规范中使用了 control:控件。

A control's value is its internal state. As such, it might not match the user's current input.

表单控件的值是它的内部状态。可能与用户的当前输入不同。

规范中还举了 2 个例子:

  • "three" 输入到 number 控件(type=number)中,控件的值不变(unchanged)。

  • " [email protected]" 输入到 email 控件(type=email)中,控件的值是 [email protected](去掉了空白)。

input and textarea elements have a dirty value flag. This is used to track the interaction between the value and default value. If it is false, value mirrors the default value. If it is true, the default value is ignored.

inputtextarea 两个元素具有脏值检查标志(dirty value flag)。用来跟踪当前值(value)和默认值(default value)之间的交互。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants