开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜