Input value doesn't display. How is that possible?

后端 未结 13 2077
后悔当初
后悔当初 2021-02-04 23:54

This must be something utterly stupid that I\'ve done or am doing, but I have an input with a value attribute that simply isn\'t being displayed:

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 00:38

    I even set autocomplete to "off" with no result. I ended up putting the next jquery snippet at the document.ready event.

    myForm.find("input").each((i, el) => {
      $(el).val($(el).attr("value"));
    });
    

    Adittionally, this would be the equivalent in pure es2015:

    document.querySelectorAll("myForm input").forEach(el => {
      el.value = el.getAttribute("value");
    });
    

    If your not using a precompilor like Babel and you need compatibility for old browser's versions, change the "(el) =>" for "function(el)". I tried both codes in my scenario and worked fine.

提交回复
热议问题