【发布时间】:2014-12-29 11:41:05
【问题描述】:
我目前正在扩展和折叠keyupevent 上的文本区域的高度。但是,一旦通过敲除自定义绑定将值绑定到文本区域,我也希望文本区域初始化它的高度。有什么解决办法吗?
(仅使用 javascript)(不添加任何 jquery 库)
当前按键处理代码
var textElement = $textBox.get(0);
var textElementOriginalHeight = $textBox.height();
while ($textBox.height() > textElementOriginalHeight && textElement.scrollHeight < textElement.offsetHeight) {
$textBox.height($textBox.height() - 1);
}
var h = 0;
while (textElement.scrollHeight > textElement.offsetHeight && h !== textElement.offsetHeight) {
h = textElement.offsetHeight;
$textBox.height($textBox.height() + 1);
}
【问题讨论】:
-
显示你当前的
keyup处理代码。 -
嗨 haim770 :) 我已经添加了代码 sn-p... 这是在 keyup 方法中执行的
-
请更新您的问题并确保它包含您的情况的小副本,最好在堆栈片段中(在编辑器工具栏上)。如果您注意代码的格式,它也会有所帮助,它越容易阅读,就越容易(并且更有吸引力)。 - 另外,无论如何:您尝试过使用custom binding 了吗?
标签: html data-binding knockout.js textarea expand