How to bind to browser change of input field? (jQuery)

☆樱花仙子☆ 提交于 2019-12-01 12:33:22
Bart

I've haven't run into this myself, but it appears to be a common issue, based on a few quick Google Searches.

One easy hack you could do is set up some code that runs every second or two via setInterval, and checks to see if the field has a value.

Something like this...

var code = $('#code');
var codeTip = $('#codetip');
var interval = setInterval(function(){
    if (code.val()!=''){
        codeTip.hide();
        clearInterval(interval);
    }
}, 1000);

I had the same issue. None of the solutions I found worked nicely enough. I ended up with this:

If it doesn't matter that your input fields have a background, I handled it just in CSS.

jsfiddle

I just gave the .inputPlaceholder { z-index: -1; } so that it aligned behind the input field and then set the input { background: transparent; } so you could see the div behind it.

Google's default -webkit-autofill style has a yellow background, so that just covers up your placeholder behind it all. No need to mess around with custom plugins/events/setIntervals.

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