Why password textbox is not empty but still show error message "密码不能为空"? because google chrome messing with the form. Google chrome autofill the username and password textbox. My javascript code CANNOT detect the textbox is not empty if the textbox is filled by chrome autofill feature. All chrome autofill is yellow background. There is no way to disable autofill in chrome new version, cannot use autocomplete="false", cannot use autocomplete="off" too, even in HTML5 also cannot. So decide to hack it by css and jquery :

But above method got 2 weakness : 1) Eg : username textbox autofill "zac1987" but the user want the username textbox to be empty, css change autofill words into white color, so the user cannot see the words, so the user thought the textbox is empty, so when click submit button "zac1987" value will be inserted into database.

2) Since ccs change autofill words into white color, when browser show autocomplete / autofill choices of selection drop down list, eg : "zac1987", "Michelle", "Peter". when the user select any choice from the autocomplete drop down list, Eg, if the user select "Peter", the user cannot see the word "Peter" in the textbox because css change autofill word into white color. The worse is jquery and javascript cannot detect the textbox value is autifill word or keyboard type in word.

Since this method has 2 weakness, so I am not going to use this method. Try very hard to figure out other method on how to prevent browser autofill / autocomplete. There is no way, so use other hack. Chrome only autocompletes the first <input type="password"> and the previous <input>. So I added:

To the top of the <form> and the case was resolved.

Posted by Zac1987 on 29 April, 2016


Enter your email address:

Subscribe in a reader

Follow zac1987 on Twitter

Chatting Box


If you feel my website is informative and it is useful for you, please donate some money to support me or buy me a drink. I will continues this good works. Thank you.