简体   繁体   中英

Another Internet Explorer problem… JQuery events

Here is my spaggeti code

$("#table_exams tbody tr").click(function ()
{
    window.location.hash="#" +$(this).attr("exam_ID");
     window.location.href="/medilab/prototypes/exams/edit?examId=" + $(this).attr("exam_ID") +"&referer=" + referer;

   row_select(this);
});

$("#table_exams tbody tr td a").click(function ()
{

    window.location.hash="#" +$(this).parent().parent().attr("exam_ID");        
    var where="/medilab/prototypes/exams/edit?examId=" + $(this).parent().parent().attr("exam_ID") +"&referer=" + referer;
    window.open(where);
    row_select($(this).parent().parent());
    alert("propaganda");
    event.stopPropagation();
    event.preventDefault();
    return false;

});

The problem is that when this function is triggered

$("#table_exams tbody tr td a").click(function ()
{

the other function is triggered also.... only in IE... What can i do for this????

This line:

$("#table_exams tbody tr td a").click(function () {

Needs to be this:

$("#table_exams tbody tr td a").click(function (event) {

You're not passing the proper event into the function, I'd imagine you're getting an undefined on event.stopPropagation(); in IE.

You need to pass the event into the function. In both functions, change .click(function () to .click(function (event)

You can also add alert(event.isPropagationStopped()) to debug further if required.

I think that event.stopPropagation(); should do the trick, see jQuery docs .

$("#table_exams tbody tr td a").click(function (event)
{
    event.stopPropagation();
    window.location.hash="#" +$(this).parent().parent().attr("exam_ID");        
    var where="/medilab/prototypes/exams/edit?examId=" +     $(this).parent().parent().attr("exam_ID") +"&referer=" + referer;
    window.open(where);
    row_select($(this).parent().parent());
    alert("propaganda");
    return false;    
});

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