我正在使用 Scripatculous 自动完成器 1.9.0。我的问题是结果列表 div 的位置在 Chrome 和 Firefox 中不正确,但在 IE 中有效。结果列表 div 显示在文本框的顶部。我能够修改controls.js并解决问题,但我想知道我是否对样式表做错了什么。这是我的代码:
style.css:
div#autocomplete
{
position: relative;
}
input#query {
width:500px;
}
div#answerlist {
width:500px;
max-height:700px;
overflow-y:scroll;
overflow-x:auto;
border:1px solid #CCCCCC;
}
index.phtml:
<div id="webphone" style="width: 1000px">
<center>
<label>Search:</label>
<input type="text" name="query" id="query"></input>
</center>
<div id="answerlist"></div>
</div>
<script type="text/javascript">
new Ajax.Autocompleter("query","answerlist","index/search", {frequency: 0.5, minChars: 1});
</script>
我尝试取消嵌套 div 和所有元素的“位置”选项的许多其他变体。什么都没起作用。
然后,我开始使用controls.js Autocompleter.create 函数和onShow 函数:
controls.js:
function(element, update){
if(!update.style.position || update.style.position=='absolute') {
/***alert(update.style.position);***/
update.style.position = 'absolute';
Position.clone(element, update, {
setHeight: false,
offsetTop: element.offsetHeight
});
}
Effect.Appear(update,{duration:0.15});
};
首先,alert 函数总是返回一个空字符串,即使我明确地将答案列表的位置样式设置为相对或绝对。其次,即使脚本明确地使位置绝对并定位元素,但最终位置是不正确的!我是唯一经历过这种事的人吗?我在linux和windows上尝试了很多版本的chrome和firefox。我一定是做错了什么。当然,我可以通过注释掉这部分代码并使用绝对定位来定位 div 元素来解决该问题。但我宁愿不这样做......
I am using Scripatculous Autocompleter 1.9.0. My problem is that the position of the result list div is incorrect in Chrome and Firefox, but works in IE. The result list div appears on top of the text box. I was able to modify controls.js and fix the problem, but I am wondering if I am doing something wrong with the style sheet. Here is my code:
style.css:
div#autocomplete
{
position: relative;
}
input#query {
width:500px;
}
div#answerlist {
width:500px;
max-height:700px;
overflow-y:scroll;
overflow-x:auto;
border:1px solid #CCCCCC;
}
index.phtml:
<div id="webphone" style="width: 1000px">
<center>
<label>Search:</label>
<input type="text" name="query" id="query"></input>
</center>
<div id="answerlist"></div>
</div>
<script type="text/javascript">
new Ajax.Autocompleter("query","answerlist","index/search", {frequency: 0.5, minChars: 1});
</script>
I tried un-nesting the divs and many other variations of "position" options for all elements. Nothing worked.
Then, I started playing with controls.js Autocompleter.create function, and the onShow function:
controls.js:
function(element, update){
if(!update.style.position || update.style.position=='absolute') {
/***alert(update.style.position);***/
update.style.position = 'absolute';
Position.clone(element, update, {
setHeight: false,
offsetTop: element.offsetHeight
});
}
Effect.Appear(update,{duration:0.15});
};
First, the alert function always returns an empty string, even if I explicitly set the position style of answerlist to relative or absolute. Second, even though the script explicitly makes the position absolute and positions the element, the final position is incorrect! Am I the only one experiencing this? I tried many versions of chrome and firefox, on both linux and windows. I must be doing something wrong. Of course I can fix the problem by commenting out this part of the code and positioning the div element using absolute positioning. But I prefer not to do that...
发布评论
评论(1)
在解决同样的问题后,我找到了解决方案并在 https://prototype.lighthouseapp.com/projects/8886/tickets/1286-error-in-elementcloneposition#ticket-1286-1
那里描述了修复,但基本上是 Element。 clonePosition 具有以下内容:
必须替换为:
After struggling with the same issue, I found the solution and opened a ticket at https://prototype.lighthouseapp.com/projects/8886/tickets/1286-error-in-elementcloneposition#ticket-1286-1
The fix is described there, but basically, Element.clonePosition has the following:
That has to be replaced by: