JQuery: Get original input value

前端 未结 7 1941
面向向阳花
面向向阳花 2021-02-07 01:51

Is it possible to get the initial value of a form input field?

For example:

7条回答
  •  暖寄归人
    2021-02-07 02:50

    The DOM element has the attribute "value" which you can access by:

    element.getAttribute('value');
    

    ... which may be different from the element's property value.

    Demo

    Note that you may call .setAttribute('value', 'new value') which will actually affect any form.reset() that is called after.

提交回复
热议问题