简体   繁体   English

javascript 在 chrome 和 firefox 中的不同行为

[英]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 中,它从下到上点击,为每个页面加载。

  1. Why is this different behaviour为什么这是不同的行为
  2. Should I be using '===' instead of '=='?我应该使用'==='而不是'=='吗?

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.

相关问题 Javascript在Firefox和Chrome中的奇怪行为 - Javascript strange behaviour in firefox and chrome JS 对 Firefox 和 Chrome 中的不同行为进行排序 - JS sort different behaviour in Firefox and Chrome Firebase / Firestore测试项目在Chrome和Firefox中具有不同的行为 - Firebase/Firestore test project has different behaviour in Chrome and Firefox addEventListener 和 removeEventListener 在 Firefox/Chrome 与 Edge 中的不同行为 - addEventListener and removeEventListener different behaviour in Firefox/Chrome vs Edge chrome和firefox上的javascript null比较有所不同 - javascript null comparison different on chrome and firefox A javascript function 在 Chrome 和 Firefox 中返回不同的结果 - A javascript function returns different results in Chrome and Firefox Firefox和Chrome中的默认参数行为 - Default parameter behaviour in Firefox and Chrome encodeURIComponent()的不同行为仅适用于Firefox - Different behaviour of encodeURIComponent() in Firefox only 与Google Chrome相比,Mozilla Firefox中的JavaScript排序功能输出有所不同 - JavaScript Sort function Output is different in Mozilla Firefox Compared to Google Chrome Javascript生成的日历在mozilla firefox和chrome中显示不同 - Javascript generated calendar showing different in mozilla firefox and chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM