textarea宽度固定,自动增高代码;input高度固定,自动增宽
input高度固定,自动增宽
<input type="text" style="width:60;overflow-x:visible;overflow-y:visible;">
textarea 宽度固定,自动增高
方法一:
<textarea rows=1 cols=40 style='overflow:scroll;overflow-y:hidden;;overflow-x:hidden' οnfοcus="window.activeobj=this;this.clock=setInterval(function(){activeobj.style.height=activeobj.scrollHeight+'px';},200);" οnblur="clearInterval(this.clock);"></textarea>
方法二:
<script>
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
function ResizeTextarea(a,row){
if(!a){return}
if(!row)
row=5;
var b=a.value.split("\n");
var c=is_ie?1:0;
c+=b.length;
var d=a.cols;
if(d<=20){d=40}
for(var e=0;e<b.length;e++){
if(b[e].length>=d){
c+=Math.ceil(b[e].length/d)
}
}
c=Math.max(c,row);
if(c!=a.rows){
a.rows=c;
}
}
</script>
<textarea style="overflow: hidden; font-family: Verdana,Arial; font-style: normal; font-size: 13px; line-height: normal; " rows="4" cols="30" οnfοcus="javascript:ResizeTextarea(this,4);" οnclick="javascript:ResizeTextarea(this,4);" οnkeyup="javascript:ResizeTextarea(this,4);"></textarea>
input高度固定,自动增宽
<input type="text" style="width:60;overflow-x:visible;overflow-y:visible;">
textarea 宽度固定,自动增高
方法一:
<textarea rows=1 cols=40 style='overflow:scroll;overflow-y:hidden;;overflow-x:hidden' οnfοcus="window.activeobj=this;this.clock=setInterval(function(){activeobj.style.height=activeobj.scrollHeight+'px';},200);" οnblur="clearInterval(this.clock);"></textarea>
方法二:
<script>
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
function ResizeTextarea(a,row){
if(!a){return}
if(!row)
row=5;
var b=a.value.split("\n");
var c=is_ie?1:0;
c+=b.length;
var d=a.cols;
if(d<=20){d=40}
for(var e=0;e<b.length;e++){
if(b[e].length>=d){
c+=Math.ceil(b[e].length/d)
}
}
c=Math.max(c,row);
if(c!=a.rows){
a.rows=c;
}
}
</script>
<textarea style="overflow: hidden; font-family: Verdana,Arial; font-style: normal; font-size: 13px; line-height: normal; " rows="4" cols="30" οnfοcus="javascript:ResizeTextarea(this,4);" οnclick="javascript:ResizeTextarea(this,4);" οnkeyup="javascript:ResizeTextarea(this,4);"></textarea>