日期:2014-05-16 浏览次数:20481 次
<!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>
<title>js 文本框效果</title>
<style type="text/css">
.inputs{width:600px;height:auto; border:1px solid #ddd;margin:100px auto;line-height:20px;}
.divInputs{width:auto;height:auto;line-height:20px;min-height:20px; }
.divHistory{height:20px;width:auto;line-height:20px;float:left;display:inline; margin:0px 3px; background-color:#dee;
word-break:keep-all;/* 不换行 */
white-space:nowrap;/* 不换行 */}
.clear{clear:both;}
</style>
</head>
<body>
<div class="inputs" id='inputs'>
<div class="divInputs" id='divInputs'>
<input type='text' value="" style="float:left;border:0px;height:20px; " id='txtInput'/>
<div class='clear'></div>
</div>
</div>
<input type='button' value="查看设置的值" id="btn"/>
</body>
<script type="text/javascript">
window.onload=function()
{
var inputs=[];
var txtInput = document.getElementById("txtInput");
var divInputs = document.getElementById("divInputs");
document.getElementById("btn").onclick=function(){
alert(inputs);
} ;
document.getElementById("inputs").onclick=function(){
txtInput.focus();
} ;
txtInput.onkeydown=function(e)
{
e=e
------解决方案--------------------
event;
if(e.keyCode==13){ // 回车
var input = txtInput.value.trim();
if(input==""){
return;
}
if(inputs.indexOf(input)>-1){
alert("内容已存在");
return;
}
var div = document.createElement("div");
div.innerHTML ="<span>" +input+"</span>";