当前位置: 动力学知识库 > 问答 > 编程问答 >

how to check word is or not full filled in this div using javascript

问题描述:

this is my code:

<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>

and i fill space full in the div , but later , i will fill chinese word and english word in the div , and chinese word and english word has different length from each other,

so how to check the the word is or not full filled in the div ,

and not more(overflow) or less ,

thanks

网友答案:

You can't do that. You will either have to use a bitmap font (for each letter an image with the same size) or a fixed width font (monospaced font, e.g. Courier New and Lucida Console).

Or you can cut the text by setting overflow:hidden property for the div.

分享给朋友:
您可能感兴趣的文章:
随机阅读: