Textarea tự động tăng kích thước 2007-07-26 01:07:02


Gửi TG demo:

<?

<html>
<
body>
<
div id="alert" style="background-color: #CCC"></div>
<
center>
<
form name="doc">
<
textarea name="tx" onkeyup="mOnKup();" wrap="physical" style="height:100;overflow:auto">
thu nghiem ve tu dong tang kich thuoc
</textarea>
</
form>
</
center>
</
body>
<
script type="text/javascript">
function
mOnKup(){
var
oHeight = document.doc.tx.scrollHeight;
var
cHeight = document.doc.tx.clientHeight;
if (
cHeight+10 < oHeight) {
document.doc.tx.style.height = oHeight+2+ "px";
document.doc.tx.value += cHeight + " : " + oHeight;
}
}

</script>
</html>

?>

Tra loi 7 comment(s) uoon 2007-07-26 01:07:02

TG 2007-07-26 05:09:21

thanks, TG thử gắn vào phpbasic :)

Tra loi

SAD 2008-07-06 12:35:59

Tôi thấy
if (cHeight < oHeight) {...
chạy cũng ok mà, đâu cần +10

Tra loi

gaulucky92 2008-07-06 06:02:55

bấm Ctrl+A (select all) một lần nó nở thêm 1 dòng :D

Tra loi

choncon 2008-09-11 09:00:57

Cái này nên dùng rows++ hoặc cols++ chứ ;Trên safari và firefox thỉnh thoảng style cho textarea không chấp nhận đâu :(

Tra loi

Về Đâu 2008-09-18 03:07:39

Great post thank you.

Tra loi

deverlop extjs 2009-03-10 12:05:16

oh,thanks a lots,cảm ơn.

Tra loi

Ken Phan 2009-03-10 09:11:18

cái này chạy trên Kombai ah` Uoon ;))

Tra loi

Y kien