首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

jquery append 疑问?如何限制只能添加2个

2012-05-15 
jqueryappend 疑问?怎么限制只能添加2个input nameidstypefile/ a hrefjavascript:void(0) id

jquery append 疑问?怎么限制只能添加2个
<input name="ids" type="file"/> <a href="javascript:void(0)" id="newFile">增加附件框</a>


<SCRIPT LANGUAGE="JavaScript">
<!--

$('#newText').click(function(){
$(this.parentNode).append('<p class="mt188"><input name="ids" type="text" style="width:484px;"></p>');
$('.add_file:last').focus();
  });

//-->
</SCRIPT>
-------------------------------------
我上面代码可以添加多个,怎么判断 只能添加2个,在多点击 《增加附件框》的时候就不显示,也不用提示。

[解决办法]
可以定义一个计数器,如果大于2,就直接返回。
[解决办法]
$(this.parentNode).append('<p class="mt188"><input name="ids" type="text" style="width:484px;"></p>');这个啊

[解决办法]
人才
$('#newText').click(function(){
if($(this.parentNode).children("p").size()>2){
$(this.parentNode).append('<p class="mt188"><input name="ids" type="text" style="width:484px;"></p>');
}
$('.add_file:last').focus();
});

热点排行