<a href="/upload/20081125195529653.jpg" target="_blank"><img class="ubbimg" alt="/upload/20081125195529653.jpg" src="http://files.jb51.net/upload/20081125195529653.jpg" border="0"></a><br><div class="htmlarea"> <textarea id="runcode76559"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>随着输入文字的多少自动变化宽度的INPUT,带计数</title> <script language="javascript"> function checkLength(which) { var maxchar=20; var oTextCount = document.getElementById("char"); iCount = which.value.replace(/[^\u0000-\u00ff]/g,"aa").length; if(iCount<=maxchar) { oTextCount.innerHTML = "<font color=#FF0000>"+ iCount+""; which.style.border = '1px dotted #FF0000'; which.size=iCount+2; } else alert("请不要超过"+maxchar); } </script> <input name="words" size="2" maxlength="100" onkeyup="checkLength(this)"> <span id="char">0</span>个字符 </textarea><br><input onclick="runEx('runcode76559')" type="button" value="运行代码"> <input onclick="doCopy('runcode76559')" type="button" value="复制代码"> <input onclick="doSave(runcode76559)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>