我有一个JS文本区域自动增长,并且文本区域大于1。在示例中,文本区域的ID为1,2,3,4...
这是JS
<script type="text/javascript">
$(document).ready(function(){
$("#ctextarea").autoGrow();
});
</script>这里是文本区域:
<textarea name="comment" class="comment" maxlength="200" id="ctextarea<?php echo $msg_id;?>"></textarea>现在我怎么设置,如果我转到文本区域2,3,4...文本区会自动增长吗?
谢谢你的帮助!
发布于 2012-11-09 13:10:54
给出所有的文本区,相同的类...并在jquery中调用类选择器
HTML
<textarea name="comment" class="comment" maxlength="200" id="ctextarea<?php echo $msg_id;?>"></textarea>
<textarea name="comment" class="comment" maxlength="200" ></textarea>
<textarea name="comment" class="comment" maxlength="200" ></textarea>JQUERY
<script type="text/javascript">
$(document).ready(function(){
$(".comment").autoGrow();
});
或
您可以使用名称选择器...
$('textarea[name="comment"]').autoGrow(); // this is jus an example coz i think u 'll not have all three textarea with the same name....发布于 2012-11-09 13:11:15
假设只有那些文本域使用"comment"类,那么您可以使用该类而不是id作为选择器:
$(".comment").autoGrow();或者使用使用通用名称的属性选择器:
$('textarea[name="comment"]').autoGrow();或者使用id为:的attribute starts-with selector:
$('textarea[id^="ctextarea"]').autoGrow();类选择器是选择相似元素的最佳选择-如果需要,只需向这些元素添加另一个类。
https://stackoverflow.com/questions/13302389
复制相似问题