使用jQuery单击<a> Tag

时间:2017-04-05 08:25:17

标签: jquery

In my program, I have a <button> and I want it to click an <a> tag when clicked. I thought this code would work, but it didnt...

$("#button").click(function(){
    $("#a").trigger('click');
});

But it doesn't seem to actually cause the click to occur. Anybody know how to do this in chrome?

1 个答案:

答案 0 :(得分:1)

.trigger("click")实际上不会单击该元素,它只会触发随元素附加的点击处理程序。

使用原生click()

 $("#a").get(0).click(); //get(0) returns reference to DOM element