简体   繁体   中英

Click event is fired more than once in Internet explorer 9

I have an hyperlink as:

<a href="#" class="search">Search</a>

On clicking the hyperlink I will get pop-up and I will perform advance search with Advance Search button in pop-up dialog with the jqgrid .

After clicking Advance Search button, It will call controller and returns grid.

My button's code is:

<a id="searchResults" class="btn btn-primary">Advance Search</a>

My jquery is:

 $('.search').on('click', function () {
      search();
  });


function search() {
    $('#searchResults').unbind('click').on('click', function () {
        searchClick();
     });
}

When I am using it in Google chrome , it works fine.

But, when I'm using it in Internet explorer(Version:9) , then $('.search').on('click',function(){..}); is called more than once and my controller throws " Session timed out " exception. Finally, I will get redirected to the login page .

Actually, it is fetching the grid results on clicking Advance Search on first click event. But, if it calls for second time, then the controller throws Exception.

But I don't know why it is calling the event $('.search').on('click',function(){..}); for the second,third,... times in Internet Explorer .

How to solve this problem?

请尝试

  e.preventDefault() 

Replace .unbind("click") with .off("click") or .one("click")

function search() {
    $('#searchResults').off('click').on('click', function () {
        searchClick();
     });
}

Instead of e.stopPropagation(), I used e.preventDefault() and works fine. Thanks @Kushal Vora

I got solution and code is:

 $('.search').on('click', function (e) {
     e.preventDefault();
     search();
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM