[英]How can I change the text of a password field from javascript?
I have an chrome extension in which I want to automatically fill in a username and password field with information the user has entered already (into my application) by running external javascript on the page. 我有一个chrome扩展,其中我想通过在页面上运行外部JavaScript来自动填写用户已输入的信息(进入我的应用程序)的用户名和密码字段。 I figured out how to fill in the username, but I can't figure out how to automatically check a checkbox or fill in the password. 我想出了如何填写用户名,但我无法弄清楚如何自动检查复选框或填写密码。
Without jQuery, one can do as follows: 没有jQuery,可以做如下:
document.getElementById( "password" ).value = "Value";
document.getElementById( "checkbox" ).checked = true;
of course replacing "password"
with the ID of the password input box, and the same with "checkbox"
. 当然用密码输入框的ID替换"password"
,与"checkbox"
相同。
if you're using jQuery you can do this: 如果你使用的是jQuery,你可以这样做:
$('#password').val('whateveryouwant');
$('#checkbox').attr('checked','checked');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.