【发布时间】:2010-08-10 15:50:03
【问题描述】:
我正在通过 $.get() 加载外部 html 块,并且我想将字符计数器绑定到其中加载的任何文本区域。
通常对于这种任务,如果它是基于事件的,我会使用 live(),如果它是自定义函数,我会使用 livequery 插件。因为我一直在使用字符计数器插件,所以我一直在使用 livequery,但我无法让字符计数器在新创建的文本区域上工作。不确定粘贴我的实时查询尝试有什么意义,但无论如何都在这里!
$("textarea").livequery(function() {
$(this).charcounter(); //or whatever the name of the counter function is
});
我尝试了一些 jQuery 计数器插件,其中两个我在这里链接:
http://plugins.jquery.com/project/TextareaCharactersCounter http://brandonaaron.net/code/countable/docs
到目前为止,没有任何效果。代码/函数适用于尚未通过 jQuery $.load、$.get 或 $.post 加载的内容。
有人吗?我正在这里接近脱发阶段!
jQuery 代码,目前在 slideDown() 调用之前中断,因为 $(data).find... 行中涉及到某些内容:
$.get("lib/scripts/php/ajax/create-content-forms.php", { typeId : typeId }, function(data){
var options = {
'maxCharacterSize': 200,
'textFontSize': '12px',
'textColor': '#5C2306',
'textFamily': 'Tahoma,sans-serif',
'textAlign': 'right',
'warningColor': '#CC3300',
'warningNumber': 40,
'isCharacterCount': true,
'isWordCount': false
};
$(data).find('textarea').textareaCount(options).end().appendTo("#contentFormContent");
$("#contentForm").slideDown();
});
以及生成的 HTML 的相关 sn-p:
<fieldset>
<legend>Additional information:</legend>
<p>
<span class="fieldtext">Description:</span>
<textarea name="description" id="description" class="charLimitShort"><?php echo $description ?></textarea>
</p>
</fieldset>
【问题讨论】:
标签: jquery-plugins jquery