解析错误的javascript代码

时间:2016-08-14 05:30:12

标签: javascript php jquery

大家好我所有错误导致错误导致最后一部分,有人能指出什么是错的

错误提示:

Parse error: syntax error, unexpected '[', expecting ',' or ';'

此行出错:

 <a> onClick="editstatus('+obj.leaveRecords[aa].idleave +')" </a>

完整代码:

$.ajax({
    type: "POST",
    url: url,
    data: {'wid' : wid},
    success: function(data)
    {
        var obj = jQuery.parseJSON(data);

        $("#WorkerName").text(name + " Leave Application");

        $.each (obj.leaveType, function (bb) {

            $( "#tbody-"+obj.leaveType[bb].idleavetype ).empty();

            $.each (obj.leaveRecords, function (aa) {

                if(obj.leaveType[bb].idleavetype == obj.leaveRecords[aa].idleavetype)
                {
                    var leaveid = obj.leaveRecords[aa].idleave ;
                    console.log(leaveid);

                    $('#tbody-'+obj.leaveType[bb].idleavetype).append('<tr><td>'+obj.leaveRecords[aa].reason+'</td><td>'+obj.leaveRecords[aa].startleaveDate+'</td><td>'+obj.leaveRecords[aa].endleaveDate+'</td><td>'+obj.leaveRecords[aa].nameStatus+'</td><td>'+obj.leaveRecords[aa].name+'</td><td>'+obj.leaveRecords[aa].ApproveOn+'</td><?php if($groupid == 3){ echo '<td> <a> onClick="editstatus('+obj.leaveRecords[aa].idleave +')" </a></td>';  }?></tr>');                                          
                }                                       
            });                                     
        });                                
    }
});

提前致谢。

3 个答案:

答案 0 :(得分:0)

onClick电话'+obj.leaveRecords[aa].idleave +' 包含错误。您无需使用+'

进行换行

试试这个: <a> onClick="editstatus(obj.leaveRecords[aa].idleave)" </a>

答案 1 :(得分:0)

错误可能出在代码的这一部分:

onClick="editstatus('+obj.leaveRecords[aa].idleave +')"

尝试用这个替换它:

onClick="editstatus(obj.leaveRecords[aa].idleave)"

您不需要在函数的参数中使用'+

答案 2 :(得分:0)

PHP中的echo需要转义内部单引号:

echo '<td><a class="btn btn-warning form-group" data-toggle="modal" data-target="#arform" onClick="editstatus(\' + obj.leaveRecords[aa].idleave + \')" >Change Status</a></td>';