0

So, I have this opDiv1 set as onMouseOver="mhover(opDiv1)" but I want to change the function onMouseOver if the browser is IE.

I'm using this:

if (ie!=undefined) { //If IE detected
        $('#opDiv1').attr("onMouseOver","mhover_ie('opDiv1')")
}

However, if I use IE (any version) it doesn't change onMouseOver's function

4

2 回答 2

1

Try this...
Remove the attr onmouseover from the obj, and bind the event with jQuery like:

function addMouseEvent(){
    if (ie!=undefined) { //If IE detected
            $('#opDiv1').onmouseover(function(){
              mhover_ie('opDiv1');
            });
    } else {
            $('#opDiv1').onmouseover(function(){
              mhover('opDiv1');
            });
    }
}

jQuery(document).ready(function(){
  addMouseEvent();
});
于 2013-08-14T11:23:10.607 回答
1

You could change IE's onMouseOver-event this way

if (ie != undefined) {
    document.getElementById('opDiv1').onmouseover = function () { mhover_ie('opDiv1'); };
};

Info: Assigning a function to the onclick property does not add an attribute to the DOM node.

于 2013-08-14T11:34:10.220 回答