87,997
社区成员




<!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=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
function Type(c,o,i){
this.oC=document.getElementById(c);
this.oO=document.getElementById(o);
this.oI=document.getElementById(i);
var _this=this;
_this.init=function(){
_this.oI.onblur=_this.blurs;
_this.oI.onkeydown=_this.keydown;
_this.oI.addEventListener("input",_this.change,false);
_this.oI.onpropertychange=_this.change;
_this.oC.onclick=function(){
_this.oI.focus();
}
_this.oI.focus();
}
_this.blurs=function(e){
var text=_this.oI.value;
if(text){
_this.create(text,'text');
alert("执行了一次blur操作");
}
}
_this.keydown = function(e){
var evt=e?e: (window.event ? window.event : null);
var key=evt.keyCode||evt.which;
if (key == 13 || key == 32) {
var text=_this.oI.value;
_this.create(text,'text');
}
}
_this.change=function(e){
var L=_this.oI.value.length;
var reg = /[^\u4E00-\u9FA5\uf900-\ufa2d]/g;
var temp = _this.oI.value.replace(reg,'');
var cL=temp.length;
var width=(13+8*L+4*cL);
_this.oO.style.width=width+"px";
}
_this.create=function(value,cName){
var oNode=document.createElement("div");
oNode.innerHTML=value;
oNode.className=cName;
_this.oC.insertBefore(oNode,_this.oO);
_this.oI.value="";
_this.oI.focus();
_this.oO.style.width="13px";
}
}
window.onload=function(){
var my=new Type("container","outer","inputbox");
my.init();
}
</script>
<style>
.text{
float:left;
padding:0px 3px;
}
input{
float:left;
}
</style>
</head>
<body>
<div style="width:400px;overflow:hidden; background:#FFF; border:1px solid #999; padding:5px; word-wrap: break-word; word-break: break-all; line-height:20px; font-size:14px; " id="container">
<div id="outer" style="width:13px; float:left;">
<input style="border:none; width:100%;" id="inputbox" value=""/>
</div>
</div>
</body>
</html>