0

I have a link element (actually, all the links of a certain class) to which I have bound a click event.

Here's an example link element:

<a id="2" class="paginationclick" style="cursor: pointer;" href="">2</a>

And here's the binding:

$(".paginationclick").click(function(e) {
    displayAccountSearchResults(e);

    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    }
});

displayAccountSearchResults(e) executes fine but then the page reloads. I do not want the page to reload. Why isn't stopPropagation / cancelBubble working?

4

1 回答 1

5

你需要一个e.preventDefault

$(".paginationclick").click(function(e) {
    e.preventDefault()

    displayAccountSearchResults(e);

    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    }
});
于 2013-05-13T21:34:52.433 回答