猿问

js拼接的问题

如:


for (var j=0;j<data[i].children.length;j++) {

    navData += '<li>'

    + '<a href="'+data[i].children[j].name+'"><span class="menu-text">'+data[i].children[j].title+'</span></a>'

    + '</li>'

}

console.log('<a href="'+data[i].children[j].name+'"><span class="menu-text"></a>');

//输出为

<a href="Video/lst"><span class="menu-text"></a>

我当前的地址是http://domain.com/admin/,按照这写法,地址不是应该是http://domain.com/admin/Video...吗?为什么会变成http://domain.com/Video/lst?


慕哥6287543
浏览 454回答 1
1回答

慕田峪4524236

推荐使用模版字符串navData += `&nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; <a herf="${data[i].children[j].name}">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="menu-text">${data[i].children[j].title}</span>&nbsp; &nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; <li>`
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答