重复发贴?
给你一个边框的例子:HTML code    <head> <title></title> <style> div { border: .1em solid #900; } #border { border-width: .1em; border-style: solid; border-color: #000; } </style> </head> <body> <form id="formID"> <input type="text" size="20" value="testinput" id="inputID"/> <div id="border" style="width:144px"> <a href="#" onclick="document.getElementById('inputID').value='test1'">test1</a> </div> <div style="width:144px"> <a href="#" onclick="document.getElementById('inputID').value='test2'">test2</a> </div> <div style="width:144px"> <a href="#" onclick="document.getElementById('inputID').value='test3'">test3</a> </div> </form> </body> </html>
长度你自己调整就好了
在test1 test2 test3加link href="#"的话就可以用tab键取得焦点
在test1取得焦点的时候 按回车 input的值就变为test1
在test2取得焦点的时候 按回车 input的值就变为test2
在test3取得焦点的时候 按回车 input的值就变为test3

解决方案 »

  1.   

    4回车可为input赋值。
    =================
    不知道什么意思。。
      

  2.   


    楼主按TAB键控制哪个DIV里面元素获取焦点
    之后点击回车,文本框值就对应获取了<head>
    <title></title>
    <style>
    div {
    border: .1em solid #900;
    }
    #border {
    border-width: .1em;
    border-style: solid;
    border-color: #000;
    }
    </style> 
    </head>
        <body>
                <form id="formID">
                    <input type="text" size="20" value="testinput" id="inputID"/>
                    <div id="border" style="width:144px">
                        <a href="#" onclick="document.getElementById('inputID').value='test1'">test1</a>
                    </div>
                    <div style="width:144px">
                        <a href="#" onclick="document.getElementById('inputID').value='test2'">test2</a>
                    </div>
                    <div style="width:144px">
                        <a href="#" onclick="document.getElementById('inputID').value='test3'">test3</a>
                    </div>
                </form>
        </body>
    </html>
      

  3.   


    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <html>
    <head>
        </head>
    <style type="text/css"> 
    .main { 
    border: 1px;
    border-color: red;
    border-style: solid;
    width: 200px;

    </style> 
        <body>
            <div style="width:50px" id="divID" >
                <form id="formID">
                    <input type="text" value="testinput" id="inputID" class="main"/>
                    <div class="main">
                         <a href="#" onclick="document.getElementById('inputID').value='test1'">test1</a>
                    </div>
                    <div class="main">
                        <a href="#" onclick="document.getElementById('inputID').value='test2'">test2</a>
                    </div>
                    <div class="main">
                        <a href="#" onclick="document.getElementById('inputID').value='test3'">test3</a>
                    </div>
                </form>
            </div>
        </body>
    </html>
      

  4.   

    参考:// textutil.js文件
            var TextUtil = new Object();       
            TextUtil.autosuggestMatch = function(sText,arrValues)
            {
                var arrResult = new Array();
                if(sText != "")
                {
                    for(var i = 0;i<arrValues.length;i++)
                    {
                        if(arrValues[i].indexOf(sText) == 0)
                        {
                            arrResult.push(arrValues[i]);
                        }
                    }
                }
                return arrResult;
            }
            
            TextUtil.clear = function(oListbox)
            {
                for(var i = 0;i<oListbox.options.length;i++)
                {
                    oListbox.remove(i);
                }
            }
            
            TextUtil.add = function(oListbox,sName,sValue)
            {
                var oOption = document.createElement("option");
                oOption.appendChild(document.createTextNode(sName));
                if(arguments.length == 3)
                {
                    oOption.setAttribute("value",sValue);
                }
                oListbox.appendChild(oOption);
            }
            
            TextUtil.autosuggest = function(oTextbox,arrValues,sListboxId)
            {
                var oListbox = document.getElementById(sListboxId);
                TextUtil.clear(oListbox);
                var arrMatches = TextUtil.autosuggestMatch(oTextbox.value,arrValues);
                for(var i = 0;i<arrMatches.length;i++)
                {
                    TextUtil.add(oListbox,arrMatches[i]);
                }
            }
            
    //The end <html>
    <head>
        <title></title>
        <script type="text/javascript" src="textutil.js"></script>
        <script type="text/javascript">        
            var arrColors = ["red","orange","yellow","green","blue","indigo","violet","brown",
                            "tan","ivory","navy","aqua","white","purple","pink","gray","silver"];
            arrColors.sort();
            
            function setText(oListbox,sTextboxId)
            {
                var oTextbox = document.getElementById(sTextboxId);
                if(oListbox.selectedIndex > -1)
                {
                    oTextbox.value = oListbox.options[oListbox.selectedIndex].text;
                }
            }                 
        </script>
    </head>
    <body >
        <input type="text" value="" id="txtColor" onkeyup="TextUtil.autosuggest(this,arrColors,'lstColors')" /><br />
        <select id="lstColors" size="5" style="width:200px" onclick="setText(this,'txtColor')"></select>
    </body>
    </html>