使用具有自动完成功能的YUI布局

时间:2012-01-24 18:10:08

标签: javascript html css yui

我在同一页面中使用YUI布局和自动完成功能。问题是自动填充字段下拉列表落后于布局。 我认为问题出在z-order上,但经过一些研究后却无法找到。

以下是我所拥有的简化代码,只需将其复制到html文件即可正常工作(例如输入字母a来查看问题):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />


<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.9.0/build/resize/assets/skins/sam/resize.css" />
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.9.0/build/autocomplete/assets/skins/sam/autocomplete.css" />
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.9.0/build/assets/skins/sam/layout.css">

<link rel="stylesheet" type="text/css" href="main.css"></link>

<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/element/element-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/animation/animation-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/layout/layout-min.js"></script>



<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/datasource/datasource-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/autocomplete/autocomplete-min.js"></script>

</head>

<body class="yui-skin-sam">

<div id="header" >

<div class="header2">
    <span class="right-float topPad4px" id="myAutoComplete">
        <input class="searchInput" id="searchInput" type="text" size="25" value=""/>
        <div id="results"></div> 
        <input id="myHidden" type="hidden"> 
    </span>
</div>

</div>

<div class="mainArea">
    <div id="tree" class="tree" style="margin-left :20px">
    </div>
    <div id="center" class="centerDiv">
    </div>
</div>

<script>

(function() {
    var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;

    Event.onDOMReady(function() {
        var layout = new YAHOO.widget.Layout({
            units: [
                { position: 'top', height: 40, body: 'header', gutter: '0px'},
                { position: 'left', width: 280, resize: true, body: 'tree', scroll: true, animate: false },
                { position: 'center', body: 'center', scroll: true }
            ]
        });

        layout.render();

        Event.on('tLeft', 'click', function(ev) {
            Event.stopEvent(ev);
            layout.getUnitByPosition('left').toggle();
        });   
    });
})();

var ds = new YAHOO.util.LocalDataSource(["apples", "apricots", "bananas"]);


var ac = new YAHOO.widget.AutoComplete("searchInput", "results", ds);

</script>

</body>
</html>

我的问题是 - 我需要修改哪些自动完成下拉列表才能显示在布局顶部?

1 个答案:

答案 0 :(得分:0)

好的,在yui论坛上找到了答案,基本上我需要添加粗体项目:

{position:'top',height:28,body:'top1', scroll:null,zIndex:2 },

有关“修复隐藏菜单”部分的详细信息,请参阅http://developer.yahoo.com/yui/examples/layout/menu_layout.html