查找并复制Chrome中的onclick行为?

时间:2019-01-24 23:15:22

标签: javascript html

此页面https://www.betbrain.co.uk/next-matches/上有一个带有“高级”文本的按钮。检查页面时的代码:

<a data-nmtab="nmAdvancedFiltersTab" class="MMLink" href="#" title="Filter 
the next matches with advanced tools">Advanced<span class="Hideable"> 
Filters</span></a>

单击该按钮后,将显示一些过滤器选项。有人告诉我,它的附加功能是通过addEventListener调用设置的。因此,我在元素窗口中搜索了addEventListener调用,但没有发现任何迹象表明单击时该行为与按钮的行为有关。然后,我为鼠标单击设置事件侦听器断点,这将我带到此功能(但位于源选项卡中的本地文件“ index”中):

add: function(a, c, d, e, g) {
            var h, i, j, k, l, m, n, o, p, q, r, s;
            if (!(a.nodeType === 3 || a.nodeType === 8 || !c || !d || !(h = f._data(a)))) {
                d.handler && (p = d,
                d = p.handler,
                g = p.selector),
                d.guid || (d.guid = f.guid++),
                j = h.events,
                j || (h.events = j = {}),
                i = h.handle,
                i || (h.handle = i = function(a) {
                    return typeof f != "undefined" && (!a || f.event.triggered !== a.type) ? f.event.dispatch.apply(i.elem, arguments) : b
                }
                ,
                i.elem = a),
                c = f.trim(I(c)).split(" ");
                for (k = 0; k < c.length; k++) {
                    l = A.exec(c[k]) || [],
                    m = l[1],
                    n = (l[2] || "").split(".").sort(),
                    s = f.event.special[m] || {},
                    m = (g ? s.delegateType : s.bindType) || m,
                    s = f.event.special[m] || {},
                    o = f.extend({
                        type: m,
                        origType: l[1],
                        data: e,
                        handler: d,
                        guid: d.guid,
                        selector: g,
                        quick: g && G(g),
                        namespace: n.join(".")
                    }, p),
                    r = j[m];
                    if (!r) {
                        r = j[m] = [],
                        r.delegateCount = 0;
                        if (!s.setup || s.setup.call(a, e, n, i) === !1)
                            a.addEventListener ? a.addEventListener(m, i, !1) : a.attachEvent && a.attachEvent("on" + m, i)
                    }
                    s.add && (s.add.call(a, o),
                    o.handler.guid || (o.handler.guid = d.guid)),
                    g ? r.splice(r.delegateCount++, 0, o) : r.push(o),
                    f.event.global[m] = !0
                }
                a = null
            }
        },

这简直让我感到困惑。最后,如果甚至可以找到其行为的代码,就好像它具有onclick属性一样,是否可以在页面上执行此代码而无需亲自单击按钮?

1 个答案:

答案 0 :(得分:0)

运行该程序如何?

document.querySelectorAll('a[data-nmtab="nmAdvancedFiltersTab"]')[0].click()