开发者

document.getElementById doesnt work with "input id", how can I do it? [+Greasemonkey]

开发者 https://www.devze.com 2022-12-29 01:08 出处:网络
I have this line on a website <input type=\"text\" autocomplete=\"off\" value=\"\" maxlength=\"20\" class=\"shipBox\" name=\"firstName\" id=\"firstName\">

I have this line on a website

<input type="text" autocomplete="off" value="" maxlength="20" class="shipBox" name="firstName" id="firstName">

and I want my greasemonkey to automatically fill this...

I'm trying this but had no success

document.getElementById("firstName").setAttribu开发者_StackOverflow社区te("autocomplete", "on");
document.getElementById("firstName").value = "Bruno"


What you're doing is basically the correct way.

The usual reaqson for this not working is a second element with the same ID somewhere in the document.

By the way, setAttribute is not the recommended way of setting an attribute in HTML, as I've been reminded today. A simple ...getElementById("firstName").autocomplete = 'on' will do.

0

精彩评论

暂无评论...
验证码 换一张
取 消