如何用javascript点击一个href?

时间:2016-01-18 16:55:54

标签: javascript events

我想点击现有的UPDATE myschema.mytable SET DateNumber='1' WHERE WEEKDAY(OrderDate) BETWEEN 0 AND 0

代码:

<a href="">

3 个答案:

答案 0 :(得分:2)

el.click是一个函数,您必须将其命名为:

el.click();

答案 1 :(得分:1)

您可以尝试window.location

var els = document.getElementsByTagName("a");
for (var i = 0, l = els.length; i < l; i++) {
    var el = els[i];
    if (el.href === 'https://www.messenger.com/t/someperson') {
        window.location = el.href;
    }
}

答案 2 :(得分:1)

试试这个:

    var els = document.getElementsByTagName("a");
    for (var i = 0, l = els.length; i < l; i++) {
        var el = els[i];
        if (el.href === 'https://www.messenger.com/t/someperson') {

           el.click();
        }
    }