innerHtml追加元素时input值被清空

innerHtml追加元素时input值被清空

场景:动态追加元素时,已填写的input内容被清空

document.getElementById('tbodyGoods').innerHTML += html;

解决方法

 <input type="text" onchange="onChangeVal(this);" value="" name="" />
function onChangeVal(e) {
    
    
    e.setAttribute("value", e.value);
} 

猜你喜欢

转载自blog.csdn.net/qq_36678880/article/details/126650770