自动填充表格没有ID TAMPERMONKEY
我是Tampermonkey的新手,我想自动填写表格,但没有ID ...我已经尝试了一些代码,但没有工作
源
<input type="text" name="user_email" class="form-control-input" value="" placeholder="Enter your Email" onselectstart="return false" onpaste="return false;" oncopy="return false" oncut="return false" ondrag="return false" ondrop="return false" autocomplete="off">
代码已经测试过
var mail = "[email protected]";
document.getElementsByClassName('form-control-input').value = mail;
i'm a newbie with tampermonkey and i want to auto fill a form but has no id ...i already tried some codes but doesnt work
source
<input type="text" name="user_email" class="form-control-input" value="" placeholder="Enter your Email" onselectstart="return false" onpaste="return false;" oncopy="return false" oncut="return false" ondrag="return false" ondrop="return false" autocomplete="off">
code already tested
var mail = "[email protected]";
document.getElementsByClassName('form-control-input').value = mail;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我个人更喜欢在TampermonKey中使用纯JavaScript而不是使用jQuery,因为它可以使我更有控制力,例如在DOM准备就绪时加载脚本。 IE将函数包装在$(文档)中。dready(function()...
您可以尝试一下(确保更改@match)
I personally prefer to use jQuery over pure javascript in tampermonkey because it gives me more control such as loading the script when the DOM is ready. i.e. wrap the function in a $(document).ready(function() ...
you can try this out (make sure to change the @match)????
更改
class
<代码> ID 或queryselector
。使用getElementsByClassName()
将返回Nodelist的集合。因此,在这种情况下考虑一个数组。如果您使用getElementsByClassName()
您告诉dom “嘿,我想处理许多事情” ,所以要添加string 对“这些事物的数量” ,您需要一个一个一个一个,并给他们
value
即,您需要循环浏览此节点符号并执行您想要的“这些数量” 。在您的情况下,何时使用getElementsByClassName
,由于您仅处理一个输入,因此更轻松地使用
id
进行选择。如果您说的是10个不同的输入
您需要使用prefl
的字段,则使用getelementsbyclassName()
,但是如果您只有2个或2个或3个字段,我建议只给每个字段一个唯一的id
,然后使用Change
class
toid
orquerySelector
. UsinggetElementsByClassName()
will return a collection of NodeList. So think of an array in this instance. If you usegetElementsByClassName()
you're telling the DOM "Hey I want to work on a number of things" so in order to add thatstring
value to " these number of things", you need to go through them one by one and give them thevalue
i.e you will need to loop through this NodeList and do what you want on "these number of things".When to use getElementsByClassName
In your case, since you're only working on one input, it's easier to select using
id
and go with that. If you have say 10 differentinput
fields that you need to use aprefill
for then usegetElementsByClassName()
but if you only have like 2 or 3 fields i recommend just giving each one a uniqueid
and using that