繁体   English   中英

找出文本何时超过contenteditable div

[英]Find out when text is over contenteditable div

我想知道,当我的文字遍历内容可编辑div时。

I dont want to have a scroll or anything, just as it is.

我想要的是阻止(不要隐藏溢出,阻止!!)任何低于div的文本。

这是我的JSFiddle与我的问题。

http://jsfiddle.net/N4tTp/1/

提前致谢。

<html>
<head>
<style>
    div.block{margin:20px;width:400px;height:100px;overflow:hidden;}
 //defined some style just for demonstration
</style>
<body>
    <div  class="block" contenteditable="true" onkeyup="ManageOverflow(event)">
    Block Content
    </div>  
</body>
<script>
function ManageOverflow(event){
    if(event.target.scrollHeight > event.target.clientHeight){
        //your action here
    }
}

</script>
</html>

正如其他人所说,你可以使用text-overflow: ellipsis ,但遗憾的是,这只适用于一行(不是多行)

text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;

如果你想要多行,你将不会得到省略号

overflow: hidden;

没有省略号的多行示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM