如何使用javascript检查此div中的单词是否已满

如何使用javascript检查此div中的单词是否已满,javascript,Javascript,这是我的代码: <div id="a" style="position:absolute;top:300px;width:100px;height:100px;background:red;color:black;word-wrap:break-word;"> <div id='a2' contenteditable=true ></div> </div> <script type="text/javascript">

这是我的代码:

<div id="a" style="position:absolute;top:300px;width:100px;height:100px;background:red;color:black;word-wrap:break-word;">
    <div id='a2' contenteditable=true ></div>
</div>
<script type="text/javascript">
    String.prototype.repeat = function(n) {
        return new Array(1 + parseInt(n, 10)).join(this);
    }

    var s=$('#a').width()/4*$('#a').height()/19;
    $('#a2').html('&nbsp;'.repeat($('#a').width()/4*parseInt($('#a').height()/19)))

    $('#a2').click(function(){
        alert('sss')
    })

</script>

String.prototype.repeat=函数(n){
返回新数组(1+parseInt(n,10)).join(this);
}
var s=$('a').width()/4*$('a').height()/19;
$('#a2').html(''.repeat($('#a').width()/4*parseInt($('#a').height()/19)))
$('#a2')。单击(函数(){
警报(‘sss’)
})
我在div中填充了所有的空格,但是稍后,我会在div中填充中文单词和英文单词,中文单词和英文单词的长度不同

那么如何检查div中的单词是否已满

而不是更多(溢出)或更少


谢谢你不能那样做。您必须使用位图字体(对于每个字母,图像大小相同)或固定宽度字体(等距字体,例如Courier New和Lucida Console)

也可以通过设置div的
overflow:hidden
属性来剪切文本