jq点击增加一段html
更新:HHH   时间:2023-1-7


<!--添加广告位信息开始-->
<div class="all" >
    <div class="widget-header">
        <h5>广告位明细(最多5条)</h5><div ><h5 id="newyz1">+增加</h5></div>
    </div>
    <div class="one1">
        <div class="contract-contracttype">
            <div class="form-group field-contract-contracttype required has-success">
                <label class="col-sm-1 control-label no-padding-right" for="receivableamount[contractId]">广告位</label>
                <div class="col-lg-2">
                    <input type="hidden" class="advertId" name="advertId[]" id="advertId" value="">
                    <input type="hidden" class="advertname1" name="advertname1[]" id="advertname1" value="">
                    <select id="port" class="form-control port" name="port[]" onchange="checkadvertname(this);">
                        <?php foreach($port as $key=>$value):?>
                        <option value="<?=$value['key']?>"><?=$value['value']?></option>
                        <?php endforeach;?>
                    </select>
                </div>
                <div class="col-lg-2">
                    <select id="page" class="form-control page" name="page[]" onchange="checkadvertname(this);">
                        <?php foreach($page as $key=>$value):?>
                            <option value="<?=$value['key']?>"><?=$value['value']?></option>
                        <?php endforeach;?>
                    </select>
                </div>
                <div class="col-lg-2">
                    <select id="advertname" class="form-control advertname" name="advertname[]" onchange="getadvert(this)">
                        <option value="0">请选择广告位</option>
                    </select>
                </div>

            </div>
        </div>
        <div class="form-group field-applypay-paymenttime">
            <label class="col-sm-1 control-label no-padding-right" for="applypay-paymenttime">发布时间</label>
            <div class="col-sm-3 col-lg-2">
                <div class="input-group">
                    <span class="input-group-addon"><i class="icon-calendar bigger-110"></i></span>
                    <input class="form-control date-picker datetime-picker3" id="projectStime" name="projectStime[]" data-date-format="dd-mm-yyyy" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text">
                    <em >-</em>
                </div>
            </div>
            <div class="col-sm-3 col-lg-2">
                <div class="input-group">
                    <span class="input-group-addon"><i class="icon-calendar bigger-110"></i></span>
                    <input class="form-control date-picker datetime-picker3" id="projectEtime" name="projectEtime[]" data-date-format="dd-mm-yyyy" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text">
                </div>
            </div>
        </div>
        <div class="form-group field-receivableamout-reason required">
            <label class="col-sm-1 control-label no-padding-right" for="receivableamout-reason">备注说明</label>
            <div class="col-lg-5"><input type="text" id="receivableamout-reason" class="form-control" name="reason[]" maxlength="100"></div>
            <div class="col-lg-3">
                <div class="help-block"></div></div>
        </div>

    </div>
    <span class="form-group" id="xx">

    </span>
    <div class="form-group field-receivableamout-reason required">
        <label class="col-lg-1 control-label no-padding-right" for="receivableamout-reason">上传附件</label>
        <div class="col-lg-11 wdata1">
            <div class="col-lg-3 btnimg">
                <label for="uploadImg" class="btn btn-primary fileimg"><i class="fa-plus-sign"></i>
                    <span>上传</span>
                    <input  class="UploadImg" data="1"  type="file" name="files[]"  multiple></label>
                </label>
            </div>

        </div>
    </div>
</div>
<!--添加广告位信息结束-->
 $("#newyz1").bind('click',function() {
                    _addnum++;
                    var num=_addnum;
                    console.log(num);
                    if($(".one1").length>4){
                        layer.msg("最多5条数据");
                        return false;
                    }
                    var html='<div class="one1">\n' +
                        '                <div class="contract-contracttype">\n' +
                        '                    <div class="form-group field-contract-contracttype required has-success">\n' +
                        '<input type="hidden" class="advertId" name="advertId[]" id="advertId" value="">\n'+
                        ' <input type="hidden" class="advertname1" name="advertname1[]" id="advertname1" value="">\n'+
                        '                        <label class="col-sm-1 control-label no-padding-right" for="receivableamount[contractId]">广告位</label>\n' +
                        '                    <a href="javascript:void(0)" class="khnimus1" title="" id="newyz1" data-original-title=""><i class="icon-trash bigger-130"></i></a>\n'+
                        '                        <div class="col-lg-2">\n' +
                        '                            <select id="port" class="form-control port" name="port[]" onchange="checkadvertname(this);">\n';
                    for (var i=0;i<ports.length;i++){
                        html+='<option value='+ports[i]['key']+'>'+ports[i]['value']+'</option>';
                    }
                    html+='</select>\n' +
                        '                        </div>\n' +
                        '                        <div class="col-lg-2">\n' +
                        '                            <select id="page" class="form-control page" name="page[]" onchange="checkadvertname(this);" >\n';
                    for (var i=0;i<pages.length;i++){
                        html+='<option value='+pages[i]['key']+'>'+pages[i]['value']+'</option>';
                    }
                    html+='</select>\n' +
                        '                            </select>\n' +
                        '                        </div>\n' +
                        '                        <div class="col-lg-2">\n' +
                        '                            <select id="advertname" class="form-control advertname" name="advertname[]" onchange="getadvert(this)" >\n' +
                        '                                <option value="0">请选择广告位</option>\n' +
                        '                            </select>\n' +
                        '                        </div>\n' +
                        '\n' +
                        '                    </div>\n' +
                        '                </div>\n' +
                        '                <div class="form-group field-applypay-paymenttime">\n' +
                        '                    <label class="col-sm-1 control-label no-padding-right" for="applypay-paymenttime">发布时间</label>\n' +
                        '                    <div class="col-sm-3 col-lg-2">\n' +
                        '                        <div class="input-group">\n' +
                        '                            <span class="input-group-addon"><i class="icon-calendar bigger-110"></i></span>\n' +
                        '                            <input class="form-control date-picker datetime-picker3" id="projectStime" name="projectStime[]" data-date-format="dd-mm-yyyy" onfocus="WdatePicker({dateFmt:\'yyyy-MM-dd\'})" type="text">\n' +
                        '                            <em >-</em>\n' +
                        '                        </div>\n' +
                        '                    </div>\n' +
                        '                    <div class="col-sm-3 col-lg-2">\n' +
                        '                        <div class="input-group">\n' +
                        '                            <span class="input-group-addon"><i class="icon-calendar bigger-110"></i></span>\n' +
                        '                            <input class="form-control date-picker datetime-picker3" id="projectEtime" name="projectEtime[]" data-date-format="dd-mm-yyyy" onfocus="WdatePicker({dateFmt:\'yyyy-MM-dd\'})" type="text">\n' +
                        '                        </div>\n' +
                        '                    </div>\n' +
                        '                </div>\n' +
                        '                <div class="form-group field-receivableamout-reason required">\n' +
                        '                    <label class="col-sm-1 control-label no-padding-right" for="receivableamout-reason">备注说明</label>\n' +
                        '                    <div class="col-lg-5"><input type="text" id="receivableamout-reason" class="form-control" name="reason[]" maxlength="100"></div>\n' +
                        '                    <div class="col-lg-3">\n' +
                        '                        <div class="help-block"></div></div>\n' +
                        '                </div>\n' +
//                            ' <div class="form-group field-receivableamout-reason required">\n' +
//                        '                    <label class="col-lg-1 control-label no-padding-right" for="receivableamout-reason">上传附件</label>\n' +
//                        '                    <div class="col-lg-11 wdata'+num+'">\n' +
//                        '                        <div class="col-lg-3 btnimg">\n' +
//                        '                            <label for="uploadImg" class="btn btn-primary fileimg"><i class="fa-plus-sign"></i>\n' +
//                        '                                <span>上传</span>\n' +
//                        '                                <input  class="UploadImg" data="'+num+'"  type="file" name="files[]"  multiple></label>\n' +
//                        '                            </label>\n' +
//                        '                        </div>\n' +
//                        '                    </div>\n' +
//                        '                </div>\n'+
                    '</div>';
                    $('#xx').append(html);

                    //jq上传插件开始
                    $(".UploadImg").fileupload({
                        url: 'http://imgapi.qq.com/upload/php/upload.php',
                        sequentialUploads: true,
                        formData: {"app": 'brzy'},
                        returnType: "json",
                        acceptFiles: "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/*,p_w_picpath/*,.pdf,.zip,.rar,.doc,.docx",
                        dataType: 'json',

// 上传完成后的执行逻辑
                        done: function (e, data) {
                            var n = data.jqXHR.responseText;
                            var an = JSON.parse(n);
                            // console.log(an);
                            layer.closeAll();
                            // if(typeof(_clickBut)=='undefined'){
                            //     var _clickBut='';
                            // }
                            _clickBut = $(this).attr('data');//哪个按钮被点击了
                            console.log($(this));
                            callback(an.url);
                        },
// 上传过程中的回调函数
                        progressall: function (e, data) {
                            layer.load(0, {shade: false});
                        }
                    });

                    //jq插件结束
                    $(".khnimus1").live('click',function(){
                        $(this).parents(".one1").remove();
                    });
                });


返回web开发教程...