Jquery - copying an input to a div with keyup paste, having an issue with autofilled data

一笑奈何 提交于 2020-01-06 18:37:18

问题


I am using ('keyup paste', function() to fill a <div>, but I do not know what to do when someone uses autofill. Also I am using cookies for a previous visitors that filled out the form. So I would like to also know how to fill the div when someone uses autofill or has the field populated with a cookie.

Here is my current script:

$(function () {
     $('#Website').on('keyup paste', function() {
    var self = this;
    setTimeout(function() {
      var str = $(self).val();
      $("#viewer").text(str.replace(/^http\:\/\//, ''));
    }, 0)
    })
});

回答1:


Try this:

$(function () {
     $('#Website').on('keyup blur paste', function() {
    var self = this;
    setTimeout(function() {
      var str = $(self).val();
      $("#viewer").text(str.replace(/^http\:\/\//, ''));
    }, 0)
    })
});


来源:https://stackoverflow.com/questions/20369344/jquery-copying-an-input-to-a-div-with-keyup-paste-having-an-issue-with-autofi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!