Javascript 在呈现页面后附加onmouseover?
你好, 第一次呈现页面时,我的div元素如下所示:Javascript 在呈现页面后附加onmouseover?,javascript,jquery,html,css,internet-explorer-6,Javascript,Jquery,Html,Css,Internet Explorer 6,你好, 第一次呈现页面时,我的div元素如下所示: <div onmousedown="this.className='showhideExtra_down_click';" onmouseout="this.className='showhideExtra_down';" onmouseover="this.className='showhideExtra_down_hover';" class="showhideExtra_down" id="extraFilterD
<div onmousedown="this.className='showhideExtra_down_click';"
onmouseout="this.className='showhideExtra_down';"
onmouseover="this.className='showhideExtra_down_hover';"
class="showhideExtra_down" id="extraFilterDropDownButton"> </div>
<div onmousedown="this.className='showhideExtra_down_click';"
onmouseout="this.className='showhideExtra_down';"
onmouseover="this.className='showhideExtra_down_hover';"
class="showhideExtra_down" id="extraFilterDropDownButton"> </div>
您可以使用:
$('#selector').live('mouseover',function(){//something todo when mouse over})
live()允许动态更改
(您也可以对“mouseout”执行相同的操作)要扩展@maniator的正确答案,我将使用:
$("#some_id").live("hover",
function() {
// do on mouseover
},
function() {
// do on mouseout
});
这就是我的结局:
$("#extraFilterDropDownButton").hover(function() {
if($('#divCategoryFilter').css("display") == 'block'){
$(this).attr('class','showhideExtra_up_hover');
}
else{
$(this).attr('class','showhideExtra_down_hover');
}
},
function() {
if($('#divCategoryFilter').css("display") == 'block'){
$(this).attr('class','showhideExtra_up');
}
else{
$(this).attr('class','showhideExtra_down');
}
});
但是,这还没有在IE6中测试。为什么要使用内嵌JS?jQuery(正如您的问题被标记的那样)当然可以处理
hover()
函数。以及从元素标记中删除单击处理程序。@我想是的,jquery已经获得了很好的ie 6支持,但自从我尝试它以来已经有一段时间了。这看起来很奇怪,但我无法在mouseout上运行第二个函数?@SnowJim,这可能是因为hover
或mouseover mouseout
事件组合相对较新(jQuery 1.4.1)所以您可以做的是1)使用2个函数或2)升级jQuery,请参见:我正在使用jQuery-1.4.1。我曾经盘旋过这项工作:(在主帖子中使用我的编辑)
$("#extraFilterDropDownButton").hover(function() {
if($('#divCategoryFilter').css("display") == 'block'){
$(this).attr('class','showhideExtra_up_hover');
}
else{
$(this).attr('class','showhideExtra_down_hover');
}
},
function() {
if($('#divCategoryFilter').css("display") == 'block'){
$(this).attr('class','showhideExtra_up');
}
else{
$(this).attr('class','showhideExtra_down');
}
});