jquery獲取當前按鈕、截取字符串、字符串拼接、動態循環添加元素


截取字符串;字符串拼接;動態循環添加元素:
獲取當前按鈕:

{data : null, render: function(data, type, row ) {
    var loginName = $("#loginName").val();
    var div = $("<div class='btn-group'></div>");
    var button1 = $("<button role='download' value='" + row[5] + "' name='download'  class='btn btn-xs btn-info glyphicon glyphicon-save' title='下載'></button>");
    var button2 = $("<button role='pass' name='edit' " +
        "data-templatename='"+ row[1] + "' " +
        "data-reportsumid='" + row[0] + "' " +
        "data-cycle='" + row[2] + "' " +
        "data-sumpeople='" + row[4] + "' " +
        "class='btn btn-xs btn-info glyphicon glyphicon-edit' title='傳閱'></button>");
        if(row[4]!=loginName&&row[6]=='1'){//已匯總但登錄人不是匯總人時不能下載
            button1.attr("disabled", true);
        }
        if($("#ifPassRole").val()=="no"){
            button2.attr("disabled",true);
        }
        div.append(button1).append(button2);
    return div[0].outerHTML;
}
showPassModel : function(e){
    var viewSelf = this;//獲取按鈕對象,不能直接取到當前操作按鈕,需要轉換。
    var $btn=$(e.currentTarget);  //獲得當前操作按鈕
    var templateName = $btn.data('templatename');  //獲取當前按鈕綁定的數據 var reportSumId = $btn.data('reportsumid');
    $.ajax({
        type:"POST",
        url:$$ctx + "/reportResultQuery/queryUsersByRoleId",
        data:{
            roleId:"480"
        },
        success:function(result){
            $("#div-passName").html("");
            var htmlContent = "";
            $.each(result.data,function(i,item){            //動態循環添加元素
                htmlContent += '<input name="checkedUser" type="checkbox" value="'+item.ssoId+'" />'+"&nbsp;&nbsp;"+item.userName+'</br>';
            });
            $(htmlContent).appendTo($("#div-passName"));
        }
    });
    $("#passModal").modal("show");
    viewSelf.saveFunction(templateName,reportSumId);        //傳遞參數
},
saveFunction : function(templateName,reportSumId){
    $("button[role='saveFunction']").click(function(){
        var str1 = "";
        $("input[name='checkedUser']:checked").each(function(){
            str1 += $(this).val()+",";                                //checkbox    獲取選中數據    $.each();
        });
        $.ajax({
            type:"POST",
            url:$$ctx + "/reportResultQuery/savePassUser",
            data:{
                readUserId:str1.substring(0, str1.length-1),            //截取字符串    String.substring();
                templateName:templateName,
                reportSumId:reportSumId
            },
            success:function(result){
                $("button[role='saveFunction']").unbind("click");        //解綁按鈕,防止多次彈出    $.unbind("click");
            }
        });
        $("#passModal").modal("hide");
    });
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM