jquery - 自动填充弹出框移动html

标签 jquery html css

我正在使用的以下代码(注意 http://www.nodstrum.com/2007/09/19/autocompleter/)是文本框的自动填充功能。演示在这里 - http://res.nodstrum.com/autoComplete/ 问题是,如果您输入“t”,autofil 弹出框会将其余的 html 移动到它下面。 我该如何解决?我试过使用 z-index 但无法正常工作。

<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">-->
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Auto Suggest</title>

<script type="text/javascript" src="jquery-1.2.1.pack.js"></script>

<script type="text/javascript">
function lookup(inputString) {
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $('#suggestions').hide();
    } else {
        $.post("rpc.php", {queryString: ""+inputString+""}, function(data){
            if(data.length >0) {
                $('#suggestions').show();
                $('#autoSuggestionsList').html(data);
            }
        });
    }
} // lookup

function fill(thisValue) {
    $('#inputString').val(thisValue);
    setTimeout("$('#suggestions').hide();", 200);
}
</script>

<style type="text/css">
body {
    font-family: Helvetica;
    font-size: 11px;
    color: #000;
}

h3 {
    margin: 0px;
    padding: 0px;   
}

.suggestionsBox {
    position: relative;
    left: 30px;
    margin: 10px 0px 0px 0px;
    width: 200px;
    background-color: #212427;
    -moz-border-radius: 7px;
    -webkit-border-radius: 7px;
    border: 2px solid #000; 
    color: #fff;
}


.suggestionList {
    margin: 0px;
    padding: 0px;
}

.suggestionList li {

    margin: 0px 0px 3px 0px;
    padding: 3px;
    cursor: pointer;
}

.suggestionList li:hover {
    background-color: #659CD8;
}
</style>

</head>

<body>


<div>
    <form>
        <div>
            Type your county:
            <br />
            <input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
        </div>

        <div class="suggestionsBox" id="suggestions" style="display: none;">
            <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
            <div class="suggestionList" id="autoSuggestionsList">
                &nbsp;
            </div>
        </div>
        HERE
    </form>
</div>

最佳答案

试试 position:fixed

   .suggestionsBox {
    position: fixed;
    left: 30px;
    margin: 10px 0px 0px 0px;
    width: 200px;
    background-color: #212427;
    -moz-border-radius: 7px;
    -webkit-border-radius: 7px;
    border: 2px solid #000; 
    color: #fff;
}

enter image description here

关于jquery - 自动填充弹出框移动html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18524955/

相关文章:

javascript - 如何使用 AngularJS 有条件地在按钮中显示 HTML?

javascript - 关闭和打开 jquery popUps 添加多个按钮

javascript - 中断 CSS 动画导致奇怪的转换

html - CSS3 Firefox 边框半径剪辑

javascript - jQuery 用动画改变图像并等待它触发超链接

Javascript/jQuery - 根据数值删除/添加多个元素的类

javascript - 无法在js文件中嵌入一些文本

jquery - 为什么jQuery没有:readonly selector?

javascript - 使用 javascript 操作伪元素

javascript - 带有图标的基础可切换侧边栏,如 Wordpress 仪表板