简体   繁体   English

<li> 悬停事件 <div> 内

[英]<li> hover event on <div> inside

I'm using the AJAX control toolkits autocomplete in a really old project of mine. 我在我的一个非常老的项目中使用了AJAX控制工具箱自动完成功能 I have some problem with the mouseover highlighting. 鼠标悬停突出显示时出现问题。

In the example that works, the generated <li> tags gets a mouseover event which changes their background color using inline css. 在有效的示例中,生成的<li>标记获取一个mouseover事件,该事件使用嵌入式css更改其背景颜色。 Works well. 效果很好。 However, when i change the markup from: 但是,当我从以下位置更改标记时:

<li>
    Hello world
</li>

to

<li>
    <div>Hello</div>
    <div>world</div>
</li>

The <li> element will only change background color when i hover a part of them which is not covered by one of the divs. <li>元素仅在我将鼠标悬停在div之一未覆盖的一部分上时才会更改背景颜色。

Since I can't modify the generated (and minified) javasacript, I'm looking for a quick and dirty fix. 由于我无法修改生成的(和缩小的)javasacript,因此我正在寻找一种快速而肮脏的修复程序。

I have tried to change the z-index of the elements, without success. 我试图更改元素的z索引,但没有成功。 I've also tried to find the event of the li and add it to the div. 我还尝试查找li的事件并将其添加到div中。 But I can't find a way to copy events that is not added by jquery to another element. 但是我找不到将jquery未添加的事件复制到另一个元素的方法。

Any ideas here are much appreciated. 这里的任何想法都非常感谢。

Below if the reverted minified javascript if its to any help: 如果将缩小的javascript恢复为任何帮助,则在下面:

_highlightItem: function(item) {   
    /// <summary>   
    /// Highlights the specified item   
    /// </summary>   
    /// <param name="item" type="Sys.UI.DomElement" DomElement="true" mayBeNull="false" />   
    /// <returns />   

    var children = this._completionListElement.childNodes;   

    // Unselect any previously highlighted item   
    for (var i = 0; i < children.length; i++) {   
        var child = children[i];   
        if (child._highlighted) {   
            if (this._completionListItemCssClass) {   
                Sys.UI.DomElement.removeCssClass(child, this._highlightedItemCssClass);   
                Sys.UI.DomElement.addCssClass(child, this._completionListItemCssClass);   
            } else {   
                if (Sys.Browser.agent === Sys.Browser.Safari) {   
                    child.style.backgroundColor = 'white';   
                    child.style.color = 'black';   
                } else {   
                    child.style.backgroundColor = this._textBackground;   
                    child.style.color = this._textColor;   
                }   
            }   
            this.raiseItemOut(new AjaxControlToolkit.AutoCompleteItemEventArgs(child, child.firstChild.nodeValue, child._value));   
        }   
    }   

    // Highlight the new item   
    if(this._highlightedItemCssClass) {   
        Sys.UI.DomElement.removeCssClass(item, this._completionListItemCssClass);   
        Sys.UI.DomElement.addCssClass(item, this._highlightedItemCssClass);   
    } else {   
        if (Sys.Browser.agent === Sys.Browser.Safari) {   
            item.style.backgroundColor = 'lemonchiffon';   
        } else {   
            item.style.backgroundColor = 'highlight';   
            item.style.color = 'highlighttext';   
        }   

    }   
    item._highlighted = true;   
    this.raiseItemOver(new AjaxControlToolkit.AutoCompleteItemEventArgs(item, item.firstChild.nodeValue, item._value));   
},   

Why not use CSS to add the needed highlights? 为什么不使用CSS添加所需的突出显示?

li > div:hover {
  /* Highlight Rule Here */
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM