jQuery .attr('value', 'new_value') not working?

前端 未结 11 1938
面向向阳花
面向向阳花 2020-12-10 04:56

I am trying to dynamically change the actual HTML value attribute of an input using jQuery. Although using input.attr(\'value\', \'myNewVal\'); wor

11条回答
  •  鱼传尺愫
    2020-12-10 05:47

    The dev tools show you the source code as it arrived from the server (for the value attribute), so you see the truly original value.

    If you want to alter it (and check against the new value) you can store a reference somewhere. Best would be to use the .data() method and check against that stored value.

    For usage purposes though (submitting or accessing it through JS), changing the value through the .attr() or .val() method should be enough.

提交回复
热议问题