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>
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>