可编辑div的最大长度属性 [英] max length property for an editable div
问题描述
在我的应用程序中有一个html div元素,如下所示:
< div id =DivIdcontenteditable =true style =border:1px solid black>< / div>
我需要限制可在div中输入的字符数。像给文本框给maxlength属性,我该怎么做?如果我能够在不使用javascript或jquery的情况下完成这项工作,它将非常有帮助。 有一些CSS属性,比如 max-height
或 max-width
,它们限制块级元素的宽度。
所以你可以这样编码:
I have an html div element in my application as follows 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. There are some CSS attributes like So you can code this out like this : 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. 这篇关于可编辑div的最大长度属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!< div style = '最大宽度:100px的' >内容< / DIV>
< span style ='max-width:100px;但是要小心,因为它们不能正确支持IE6:请参阅 > 。
但是,如果你只是指内容的长度,我很遗憾地说你不能用HTML做到这一点。你需要使用一块JavaScript来做到这一点。看看JQuery,这很容易做到。 <div id="DivId" contenteditable="true" style="border:1px solid black"></div>
max-height
or max-width
which do limit the width for block level elements. <div style='max-width:100px'>Content</div>
<span style='max-width:100px; display:block;'>Content</span>