简体   繁体   English

如何从javascript更改密码字段的文本?

[英]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.

相关问题 如何更改密码元素输入 JavaScript 的文本 - How do I change the text of a password element input JavaScript 如何将文字添加或更改为 <div> javascript中的元素 - How can i add or change text to a <div> element from javascript 为什么我不能通过javascript更改文本字段的值? - why i can't change value of a text field by javascript? 密码输入字段在焦点/类型上从文本更改为密码? - Password input field change from text to password on focus/type? 如何使用 Javascript 更改按钮的文本? - How can I change the text of a button with Javascript? 我如何将文本更改为单击文本本身的输入字段 - How can I change text to input field clicking on the text itself 我该如何切换 <p:password> 带有复选框的文本和密码字段,请取消选中 - how can i toggle a <p:password> field to text and password with a checkbox check uncheck 如何在带有星号(密码字段)的文本框字段中显示最后 3 个字符? - How can I display last 3 character in text box field with asterisk (password field)? 如何使输入用户名字段的文本复制到密码字段,使它们相同? - How can I make the text entered into the username field copy to the password field so they are the same? 如何通过输入屏蔽使文本字段表现得像密码字段? - How I can make text field behave like password field through input masking?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM