在javascript中,差异input.value = val与input.setAttribute('value',val)?

cc *_*ung 3 javascript attributes dom properties

在javascript中,将HTMLElement属性设置为赋值与使用之间的区别是什么setAttribute().以下是从铬会话,导致我相信这一个区别:

> i = document.createElement('input');
<input>
> i.value = 'abc';
"abc"
> i
<input>?
> i.setAttribute('value','abc');
undefined
> i
<input value=?"abc">

究竟有什么区别?这是你在屁股中字节的东西吗?


回答吧.

chrome显示属性,因此导致我的困惑.

Que*_*tin 7

在javascript中,将HTMLElement属性设置为赋值与使用setAttribute()之间的区别是什么

这取决于财产.

value属性反映当前值,value属性反映默认值.

某些属性直接映射到属性.