clone()和clone(true)的区别

jquery clone(true)和clone()的区别

clone(true)方是复制一个元素及其所有事件,
clone()方法是复制一个元素,不包含其所有事件 ,


<input type="button" prefix="addItem" id="addItem1" value="添加选项">
<input type="button" prefix="descItem" id="descItem1" value="减少选项">
<div id="option_list_1">
<div>
<font color="#FF0000"> *</font>
<span>1</span>、<input type="text" ids="option" id="opt1" msg="必填" datatype="require" require="true" size="40" name="subject[option][]" class="errinput"><span class="no" tag="err">必填</span>
图片:<input type="text" size="18" id="pic1" name="subject[image][]">
<input type="button" οnclick="uploadpic(this)" sn="1" style="width:40px" value="上传" id="upload">
<span><input type="button" οnclick="addPic(this.sn)" sn="1" style="width:50px" value="浏览..."></span>
</div>
<div>
<font color="#FF0000"> *</font>
<span>2</span>、<input type="text" ids="option" id="opt2" msg="必填" datatype="require" require="true" size="40" name="subject[option][]">
图片:<input type="text" size="18" id="pic2" name="subject[image][]">
<input type="button" style="width:40px" οnclick="uploadpic(this)" sn="2" value="上传" id="upload">
<span><input type="button" style="width:50px" οnclick="addPic(this.sn)" sn="2" value="浏览..."></span>
</div>
</div>
<div id="extra_option_1">

</div>

<script>
//增加选项
$('input[id^="addItem"]').click(function(){
var newOption = $('#option_list_1 div:first').clone(true);
newOption.find('input[name]').val('');
var n = $('#extra_option_1').find('input[name]').length/2+3;
newOption.find('span:first').html(n);
newOption.find('input[id="pic1"]').attr({id:'pic'+n});
newOption.find('input[sn="1"]').attr({sn:n});
newOption.appendTo('#extra_option_1');
});

function addPic(index){
file_select('pic'+index, 0, 1);
}
//减少选项
$('input[id^="descItem"]').click(function (){
var sn=(this.id).replace('descItem','');
var subopt = $('#extra_option_'+sn).find('div');
if(subopt.length<2) {
$('input[id="descItem"][sid='+sn+']').attr({disabled:true});
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值