javascript-tutorial / javascript-tutorial/en.javascript.info
sync between attributes and properties
- 主要语言
- HTML
- 星标
- 25.5k
- 派生
- 4k
- PR 合并指标
- 30 天内没有已合并 PR
描述
> But there are exclusions, for instance input.value synchronizes only from attribute → to property, but not back:
I don't know is it worth or not to mention (as a side note) that the sync between attributes and properties is *not* going to happen *after* a property is assigned directly. Example
```javascript
let inp = document.getElementById('search');
inp.setAttribute('value','initialValue');
inp.value === 'initialValue'; //true
inp.setAttribute('value','changedValue via setAttribute');
inp.value === 'changedValue via setAttribute'; // true;
inp.value = 'cancel all consecutive attempts to sync via setAttribute';
inp.value === 'cancel all consecutive attempts to sync via setAttribute'; // true
inp.setAttribute('value','has no effect on input.value');
inp.value === 'has no effect on input.value'; // false
inp.value === 'cancel all consecutive attempts to sync via setAttribute'; // true
```
[go to the website](https://javascript.info/dom-attributes-and-properties#property-attribute-synchronization)
贡献指南
这个仓库没有索引到贡献指南
调研方向
从链接的 DOM attributes 和 properties 部分开始,尤其是 property-attribute synchronization 示例。明确直接赋值 input.value 后文档所述的行为;如果单向同步的注意事项应放在该部分,则更新该部分;完成的标准是示例准确解释为什么之后调用 setAttribute 不会改变 input.value。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100