开发者

Jquery .click() doesn't fire for <a> tag

$(document).ready(function () {
    $(":button").click(function () {
        $(this).next('a').click();
    });
});

HTML

<div style="text-align:center">
            <input type="button" value="More" class="button">
            <a style="display:none" href="/Resource/PhysicianMaterials">aaa</a>
        </div>

In this cod开发者_如何学Goe .click() doesn't fire for tag, can anyone say what is the problem? Thanks


The click event is firing, however, a click does not go to the URL when you're talking about an anchor (that happens at the browser/native event level, it's not JavaScript triggered).

Instead you need to do that navigation yourself, like this:

$(document).ready(function () {
    $(":button").click(function () {
        window.location = $(this).next('a').attr('href');
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜