浏览器(chrome,firefox)jquery .val()不适用于自动填充的输入字段(用户名,密码) [英] browser (chrome, firefox) jquery .val() does not work for autofilled input fields (username, password)
问题描述
仅当长度不为0且用户名和密码不为空时执行此代码才能启用登录按钮,依此类推。这很好用。但是,如果我在浏览器中保存我的登录凭据并访问该网站并看到字段已预先填充,则.val()函数似乎不会返回值。如果我点击任何键,则启用登录按钮。所以函数初始化登录状态按钮似乎不起作用。是否可以为jquery显示预填充字段?
This code is executed to enable a login button only if the length isn't 0 and username and password isn't empty and so on. this works fine. But if i save my login credentials in my browser and i visit the website and see that the fields are prefilled the .val() functions seems not to return a value. if i hit any key the login button is enabled. So the function "Initialize state of login button" seems not to work. Are pre filled fields visible for jquery?
希望你理解我^^
谢谢你!
hope you understand me ^^ thank you!
ready: function() {
var view = this;
//setup subViews
view.setupSubs();
//Initialize state of login button
view.onKey();
},
"onKey": function(event) {
var view = this,
nickname = view.$('#nickname').val(),
password = view.$('#password').val();
if (!nickname || !password || nickname.length === 0 || password.length < 8) {
view.$(':submit').attr('disabled', 'disabled');
} else {
view.$(':submit').removeAttr('disabled');
}
},
推荐答案
的 NB这仅涵盖Chrome。
我最近遇到了类似的水印控件问题。 Chrome中自动填充密码输入的值对于javascript显示为空白。我假设这是来自Google的某种安全插件。所以你无法在javascript中获得价值,但是你可以测试是否一个值。
I recently had a similar issue with a watermarked control. The "value" of autofilled password inputs in chrome appears blank to javascript. I'm assuming this is a security plug of some kind from Google. So you can't get the value in javascript but you can test if there is a value.
Chrome有一个CSS选择器改进名为 -webkit-自动填充。您可以使用JQuery进行选择。这给了我们测试:
Chrome has a CSS selector refinement called -webkit-autofill. You can select on this using JQuery. Which gives us the test:
var hasHiddenValue = view.$('#password:-webkit-autofill').length > 0;
这篇关于浏览器(chrome,firefox)jquery .val()不适用于自动填充的输入字段(用户名,密码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!