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

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

    It won't change the value in the DOM explorer of most development tools. But JavaScript will still get the current values. So

    var newValue = 'new';
    $(sel).val(newValue);
    newValue == $(sel).val(); // true
    

提交回复
热议问题