解决方案 »

  1.   

    那个x其实就是一张图片或者说是一个按钮,点击后输入框内容清空。
    用keydown事件检测输入框是否为空,如果不为空则显示清空按钮,如果为空则隐藏
      

  2.   

    css控制x显示位置<style>
    .input{position:relative;}
    .input .x{display:none;text-decoration:none;position:absolute;left:190px;color:blue;font-weight:bold}
    </style>
    <div class="input"><a href="#" class="x" onclick="return clearInput(this)">x</a><input type="text" style="width:200px" onkeyup="xShow(this)" /></div>
    <script type="text/javascript">
        function clearInput(a) {
            a.parentNode.getElementsByTagName('input')[0].value = '';
            a.style.display = 'none'; 
            return false;
        }
        function xShow(ipt) {
            ipt.parentNode.getElementsByTagName('a')[0].style.display = ipt.value == '' ? 'none' : 'block'
        }
    </script>