在语法错误中找不到遗漏

时间:2017-03-06 02:03:37

标签: javascript html

document.getElementById('channels').innerHTML = '<li><a onClick="loadChannel('+channelArray[i]+')"><h4>'+memberArray[i]+'</h4><p>Member</p></a></li>';

返回:

Uncaught SyntaxError: missing ) after argument list

谁能告诉我哪里出错?

以下是整个代码段:

$(document).on("pageinit", "#vendorMessages", function() {
    var channelArray = new Array();
    var memberArray = new Array();
    pubnub.subscribe(
        {
        channelGroup: getChannelGroup()
        },
        function (status, response) {
            alert("test");
            console.log(status, response);
        }
    );
    pubnub.channelGroups.listChannels(
        {
            channelGroup: getChannelGroup()
        }, 
        function (status, response) {
            response.channels.forEach( function (channel) {
                var channelFormatted = String(channel).split("_");
                var channelMember = channelFormatted[1];
                channelArray.push(String(channel));
                memberArray.push(String(channelMember));
            })
            var i;
            for (i=0; i<channelArray.length; i++) {
                document.getElementById('channels').innerHTML = '<li><a onClick="loadChannel('+channelArray[i]+')"><h4>'+memberArray[i]+'</h4><p>Member</p></a></li>';
            }
            $("#channels").listview("refresh");
        }
    );
});

1 个答案:

答案 0 :(得分:2)

(function(event){(loadChannel(931_matt)) })

变量(和函数参数)不能以数字开头。请参阅this

想一想其他方法。