向图像的onmouseout属性添加其他功能 [英] Adding extra functions to an image's onmouseout attribute
本文介绍了向图像的onmouseout属性添加其他功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个:
<img border="0" onmouseout="hidetips();" onmouseover="showtips();" src="image.gif">
<script type="text/javascript">
$(document).ready(function() {
$("img").each(function(index){
$(this).attr("onmouseout", "hidetips();newfunction();");
});
});
</script>
我在上面尝试过,但是没有用,有人知道如何在onmouseout属性的后面添加额外的newfunction()吗?
I tried above but it is not working, anyone one know how to add extra newfunction() at behind on the onmouseout attribute?
推荐答案
使用mouseout
方法绑定事件处理程序.使用匿名函数来包含对单独函数的调用:
Use the mouseout
method to bind an event handler. Use an anonymous function to contain calls to the separate functions:
$(document).ready(function() {
$("img").mouseout(function() {
hidetips();
newfunction();
});
});
注意:它将绑定所有在jQuery对象中找到的元素,因此您不必循环.
Note: It will bind all found elements in the jQuery object, so you don't have to loop.
您还可以使用jQuery绑定showtips
函数,这样就不需要每个图像元素中的事件属性:
You can bind the showtips
function using jQuery also, so that you don't need the event attributes in every image element:
$(document).ready(function() {
$("img").mouseover(showtips).mouseout(function() {
hidetips();
newfunction();
});
});
这篇关于向图像的onmouseout属性添加其他功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文