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

前端 未结 11 1929
面向向阳花
面向向阳花 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:34

    They responses that inform you to use the .val("value") method are correct, the only way that I know of to see these changes (in the source) is using the Firefox Web Developer Plugin and clicking "View Source" -> "View Generated Source". This shows the source after DOM manipulation (i.e. calls to the .val() method) have occurred, I use it a lot when working with functions/methods that modify DOM elements.

    So to recap: [#input_id = ID of your input field]

    $("#input_id").val("new value");
    

    Then use the plugin to view the generated source and you will see the updated value.

提交回复
热议问题