網頁

2019/8/7

HTML dirty value flag

HTML <input>元素的dirty value flag。

<input><textarea>元素有一個為boolean的dirty value flag參數。在<input>剛被建立時dirty value flag預為false,當使用者透過UI或程式改變<input>的value值時dirty value flag設為true。

dirty value flag用來追蹤元素default value與value的互動關係。當dirty value flag為true時value即為default value;反之則忽略default value而value的值為使用者輸入或程式改變後的值。


引述HTML 5.3 - W3C Working Draft

Each <input> element has a boolean dirty value flag. The dirty value flag must be initially set to false when the element is created, and must be set to true whenever the user interacts with the control in a way that changes the value. (It is also set to true when the value is programmatically changed, as described in the definition of the value IDL attribute.)


引述HTML Living Standard — Last Updated 7 August 2019

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.


以上這麼多複雜的敘述是因為這是要給瀏覽器廠商(e.g. Chrome, Firefox)實作對該元素的行為描述。

總之就是<input>value一開始是default value(空字串)。當改變<input>內容時,value的值就為改變後的內容。

沒有留言:

張貼留言