Tag: textarea

使用自动resize创build一个textarea

还有另一个关于这个的线索 ,我试过了。 但是有一个问题:如果删除内容,textarea不会缩小。 我找不到任何方法缩小到正确的大小 – clientHeight值作为textarea的完整大小,而不是其内容。 该页面的代码如下。 我会很感激任何帮助或指针。 function FitToContent(id, maxHeight) { var text = id && id.style ? id : document.getElementById(id); if ( !text ) return; var adjustedHeight = text.clientHeight; if ( !maxHeight || maxHeight > adjustedHeight ) { adjustedHeight = Math.max(text.scrollHeight, adjustedHeight); if ( maxHeight ) adjustedHeight = Math.min(maxHeight, adjustedHeight); if ( adjustedHeight […]

如何从一开始就以字符方式在textarea中获得插入符号的位置?

如何使用JavaScript在<textarea>获得插入符的位置? 例如: This is| a text This is| a text 这应该返回7 。 你将如何得到它返回光标/select周围的string? 例如: 'This is', '', ' a text' 。 如果单词“is”被突出显示,那么将返回'This ', 'is', ' a text' 。