计算 contentEditable DIV 中的字符数
我使用此插件来计算输入和文本区域的字符数: http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
我还需要计算 DIV 中的字符数将“contentEditable”设置为 True。
可以修改这个插件吗?
我想我需要改变这一行中的一些内容:
var count = $(obj).val().length;
但我真的不知道 contentEditable 是如何工作的......有什么想法吗?
谢谢!
编辑:
我正在按照brettz9的建议这样做:
var method = $.inArray(obj.nodeName.toLowerCase(), ['textarea', 'input']) !== -1 ? 'val' : 'text';
var count = $(obj)[method]().length;
我只是在为其他字段执行此操作时遇到一个小问题,我需要有一个最小/最大长度(我有一个输入和一个内容可编辑)
这是条件部分:
if (other_required){
if ($(other_required).val().length > 0 && available >= 0){
$(submit_button).attr("disabled", "");
} else {
$(submit_button).attr("disabled", "disabled");
}
我不'不知道如何声明 [method] var 并将其与“other_required”一起使用
I'm using this Plugin to count chars on inputs and textareas: http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
I would need to count characters also in a DIV with the setting "contentEditable" set to True.
Is this possible modifiying this Plugin?
I think I would need to change something in this line:
var count = $(obj).val().length;
But i really don't know how the contentEditable works... Any idea?
Thanks!
Edit:
I'm doing this as brettz9 suggested:
var method = $.inArray(obj.nodeName.toLowerCase(), ['textarea', 'input']) !== -1 ? 'val' : 'text';
var count = $(obj)[method]().length;
I just have one little problem on doing this for other field I required t have a min/max lenght (I have one input and one contentEditable)
This is that conditional part:
if (other_required){
if ($(other_required).val().length > 0 && available >= 0){
$(submit_button).attr("disabled", "");
} else {
$(submit_button).attr("disabled", "disabled");
}
i don't know how to declare that [method] var and use it with "other_required"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
val()
用于获取输入值,例如文本区域、文本框等。请尝试使用text()
。编辑:
试试这个:
你的代码看起来像:
val()
is used to get input values such as textarea, textbox, etc. Trytext()
instead.EDIT:
Try this:
And your code would look like:
你可以这样做:
You can do it like this: