max length property for an editable div

心已入冬 提交于 2019-12-12 10:21:59

问题


I have an html div element in my application as follows

<div id="DivId" contenteditable="true" style="border:1px solid black"></div>

I need to limit the number of character that can be typed in the div. Like giving maxlength attribute to textbox how can I do this? Its very helpful if I am able to do it without using javascript or jquery.


回答1:


There are some CSS attributes like max-height or max-width which do limit the width for block level elements.

So you can code this out like this :

<div style='max-width:100px'>Content</div> <span style='max-width:100px; display:block;'>Content</span>

But be careful, as they do not properly support IE6 : Refer this URL .

But if you just mean length of content,I am sorry to say that you can't do that in HTML. You need to use a piece of javascript to do this. Take a look at JQuery, it's really easy to do.



来源:https://stackoverflow.com/questions/21876085/max-length-property-for-an-editable-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!