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?
答案 0 :(得分:1)
.trigger("click")
实际上不会单击该元素,它只会触发随元素附加的点击处理程序。
使用原生click()
$("#a").get(0).click(); //get(0) returns reference to DOM element