JQuery: Get original input value

前端 未结 7 1944
面向向阳花
面向向阳花 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:25

    The HTML does change. Just that the browser's default view source tool always shows you the original source fetched from server. If you use something like Firebug, you'll be able to see the dynamic changes in HTML.

    One way of getting the initial value is by storing it in an additional attribute in addition to 'value'. For example, if you serve out your HTML like:

    
    

    You can always get back the original value by calling:

    $("#one").attr("origvalue");
    

提交回复
热议问题