English 中文(简体)
从所有 < img> 标签中删除停用事件
原标题:Remove onmouseover event from all <img> tags

我这样做:

$.each($( img ), function () {
    this.unbind( onmouseover );
});

这不管用 为什么?

最佳回答

尝试像下面,

$( img ).unbind( mouseover );

不需要循环。 并且它应该是 moususeover 而不是 onmouseover

<强度 > 假设: 您正在使用 . bind 约束 mouseover 处理器

我不使用绑定 。 有些图像有粘附属性, 我想删除它们 。 我尝试$( img. removeAttr), 但它仍然不起作用 。

  1. Using inline event handler is not a standard.
  2. Since you are using jQuery, you should bind handler like below.

<强度 > 守则:

$( img ).on( mouseover , function () {
     //Your code
});

以后可以通过 .off - & gt; 解码

$( img ).off( mouseover );

(

$.each($( img ), function () {
    $(this).removeAttr( onmouseover );
});
问题回答

这里的概念代码是:

$( img )
    .unbind( mouseover )               //remove events attached with bind
    .off( mouseover )                  //remove events attached with on
    .die( mouseover );                 //remove events attached with live
    .each(function(i,el){              //and for each element
        el.onmouseover = null          //replace the onmouseover event
    });




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签