[英]javascript different behaviour in chrome and firefox
Below is my Grease monkey script/Tamper monkey to click on the buttons(multiple buttons), which has the name containing 'attach'.下面是我的 Grease 猴子脚本/篡改猴子点击按钮(多个按钮),其名称包含“附加”。 The script is working perfect, however there is a difference in Chrome and firefox.
该脚本运行良好,但 Chrome 和 firefox 存在差异。
In Firefox the click happens from top to bottom order of the 'attach'(name containing) buttons.在 Firefox 中,点击发生在“附加”(包含名称)按钮的从上到下的顺序。 In Chrome it clicks from bottom to the top, for each page load.
在 Chrome 中,它从下到上点击,为每个页面加载。
Below is my greasemonkey/tampermonkey script下面是我的greasemonkey/tampermonkey脚本
var inputs = document.getElementsByTagName('input');
for (x = 0; x < inputs.length; x++) {
myname = inputs[x].getAttribute('name');
if (myname.indexOf('attach') == 0) {
document.getElementsByName(myname) [0].click();
}
}
Try to fix little errors here and there - because one browser might auto-correct a syntax error while the others won't (which is often the case for me I've noticed)尝试在这里和那里修复小错误 - 因为一个浏览器可能会自动更正语法错误,而其他浏览器则不会(我注意到这对我来说经常发生)
var inputs = document.getElementsByTagName('input');
// Add var to keep scope in the for loop
for (var x = 0; x < inputs.length; x++) {
// Add var here or else it will be global
var myname = inputs[x].getAttribute('name');
if (myname.indexOf('attach') == 0) {
// Syntax error: remove ' ' after (myname)
document.getElementsByName(myname)[0].click();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.