Getting the value of autofilled inputs - Jquery

拈花ヽ惹草 提交于 2020-02-06 06:33:42

问题


So, as some browsers auto-fill sign in forms, it causes an issue with my interactive placeholders. The placeholder is a <span> element with some text in, which moves above the input itself when focussed. Upon the browser inserting the data it has 'remembered', how would I be able to detect its presence, and it's value?

Please note, that it is the auto-completed value of the input which I wish to grab.


回答1:


Using the following code, I have managed to achieve the result I wished for:

setTimeout(function() {
    console.log($('#input').val());
});

Using a timeout allowed the browser to load itself prior to the code requesting data from it.




回答2:


Give the span an ID and run the text() method on it. Without any parameters it works as a getter.

var yourtext = $('#somespan').text();

If it was an actual textfield instead of a span, you would get the contents with the .val() method.

var yourtext = $( "#foo" ).val();


来源:https://stackoverflow.com/questions/34098975/getting-the-value-of-autofilled-inputs-jquery

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