【发布时间】:2011-02-15 00:37:18
【问题描述】:
我正在开发基于 Scriptaculous Ajax.Autocompleter 的自动完成框。
它通常可以工作,但我需要有更广泛的选择列表(见image -- 绿线 -- 320px)然后输入框(见image -- 红线 -- 155px)。
我的第一次尝试是使用 CSS 类设置各种 width(如上),但它不起作用 - 选项列表变得与输入框一样宽。
根据 Firebug,我的 CSS 类定义的 width 被 width 覆盖,由 element.style CSS 类设置,这似乎是由 Ajax.Autocompleter 定义的。
我的第二次尝试是在创建Ajax.Autocompleter 后设置width 以供选择列表
$("isearch_choices").setStyle({width: "320px"});
但它也没有用:(。
没有更多的想法:(。
如何为 Scriptaculous Ajax.Autocompleter 的选项列表设置不同的宽度?
下面是完整的代码示例:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.2/scriptaculous.js"></script>
<style>
input.iSearchInput {
width: 155px;
height: 26px;
margin-top: 7px;
line-height: 20px;
}
div.iSearchChoices {
position:absolute;
background-color:white;
border:1px solid #888;
margin:0;
padding:0;
width: 320px;
}
div.iSearchChoices ul {
list-style-type:none;
margin:0;
padding:0;
}
div.iSearchChoices ul li.selected { background-color: #ffb;}
div.iSearchChoices ul li {
list-style-type:none;
display:block;
margin:0;
padding:2px;
height:32px;
cursor:pointer;
border-bottom: 1px dotted #929292;
}
</style>
</head>
<body>
<input type="text" maxlength="255" class="input iSearchInput" name="isearch_value" id="isearch" value="Search" onfocus="this.select()">
<br>
<div id='isearch_choices' class='iSearchChoices'></div>
</script>
</body>
<script>
function iSearchGetSelectedId(text, li) {
console.log([text, li.innerHTML].join("\n"));
document.location.href = li.getAttribute("url");
}
document.observe('dom:loaded', function() {
try {
new Ajax.Autocompleter("isearch", "isearch_choices", "/url", {
paramName: "phrase",
minChars: 1,
afterUpdateElement : iSearchGetSelectedId
});
}
catch (ex) {
alert(ex);
}
$("isearch_choices").setStyle({width: "320px"});
});
</script>
</html>
并使用result链接到图像。
【问题讨论】:
标签: ajax scriptaculous autocomplete