Does javascript forbid changing the input type from password or to password?

和自甴很熟 提交于 2020-01-06 04:18:42

问题


I am using this code on the input element:

onmouseout="
$('#passwordhelp').text('');
$('#rpassword').attr('type', 'password')"

回答1:


You can't change the property type with jquery in the way you are attempting to do it. You're bumping into a browser issue:

See JQuery change type of input field




回答2:


Are you using jQuery 1.6 or above? If so try .prop(). In your case like this (Example):

onmouseout="
$('#passwordhelp').text('');
$('#rpassword').prop('type', 'password')"

Though it won't work on IE8 and below.

IMHO you shouldn't use javascript and jQuery like this. Bind your events on .ready(). But of course it's your choice...



来源:https://stackoverflow.com/questions/8548469/does-javascript-forbid-changing-the-input-type-from-password-or-to-password

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