1.自动选中输入框的文字
<input onfocus="this.select()">
2.鼠标悬停在输入框时改变边框颜色或背景色
(1)css中加入input:hover{border:1px solid #f00}
(2)<input onfocus="this.select()" onmouseover="this.style.bordercolor="#f00" onmouseout="his.style.bordercolor=""">
3.点击输入框默认文字消失
(1)<input type="text" value="请输入用户名" onfocus="if(value =="请输入用户名"){value""}" onblur="if(value==""){value="请输入用户名"}">
<input id="searchKey" type="text" name="q" value="" tips="请输入关键字"/><br />
<script language="javascript" type="text/javascript">
window.onload = function(){
var o=document.getElementByIdx_x("searchKey");
o.setAttribute("valueCache",o.value);
o.onblur = function(){ if(o.value=="")
{ o.valueCache=""; o.value=o.tips;
}
else
o.valueCache=o.value;
}
o.onfocus = function(){
o.value=o.valueCache; //光标始终在文字最后
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart('character',e.value.length);
r.collapse(true);
r.select();
}
o.onblur();
}
<script>
4.输入字时输入框边框闪烁(边框为小方型)
<Script Language="JavaScript">
function borderColor(){
if(self['oText'].style.borderColor=='red'){
self['oText'].style.borderColor = 'yellow';
}else{
self['oText'].style.borderColor = 'red';
}
oTime = setTimeout('borderColor()',400);
}
</Script>
<input type="text" id="oText" style="border:5px dotted red;color:red" οnfοcus="borderColor(this);" οnblur="clearTimeout(oTime);">
5.输入字时输入框边框闪烁(边框为虚线)
<style>
#oText{border:1px dotted #ff0000;ryo:expression(οnfοcus=function light (){with(document.all.oText){style.borderColor=(style.borderColor=="#ffee00"?"#ff0000":"#ffee00");timer=setTimeout(light,500);}},οnblur=function(){this.style.borderColor="#ff0000";clearTimeout(timer)})};
</style>
<input type="text" id="oText">
6.自动横向延伸的输入框
<input type="text" style="huerreson:expression(this.width=this.scrollWidth)" value="abcdefghijk">
7.自动向下延伸的文本框
<textarea name="content" rows="6" cols="80" onpropertychange="if(this.scrollHeight>80) this.style.posHeight=this.scrollHeight+5">输入几个回车试试</textarea>
8.只有下划线的文本框
<input style="border:0;border-bottom:1 solid black;background:;">
9.软件序列号式的输入框
<script for="T" event="onkeyup">
if(value.length==3)document.all[event.srcElement.sourceIndex+1].select();
</script>
<input name="T" size="5" maxlength="3">—<input name="T" size="5" maxlength="3">—<input name="T" size="5" maxlength="3">—<input name="T" size="5" maxlength="3">—<input name="T" size="5" maxlength="3">—<input name="T7" size="5" maxlength="3">
10.软件序列号式的输入框(完整版)
<script for="T" event="onkeyup">if(value.length==maxLength)document.all[event.srcElement.sourceIndex+1].focus();</script>