简体   繁体   English

使用JQuery进行字符串连接

[英]String Concatenation with JQuery

So far, I've been trying to make a photo album with different tabs as different albums. 到目前为止,我一直在尝试制作带有不同标签的相册作为不同的相册。 To make it work, I used href (as suggested) to link the actual tab (button) with the content but it hasn't been working out for me. 为了使其正常工作,我使用了href (如建议的那样)将实际的选项卡(按钮)与内容链接起来,但是它对我来说还没有解决。 My album has to be dynamic so the #albumID inside href has to be dynamic as well. 我的相册必须是动态的,因此href内的#albumID也必须是动态的。

this is the code. 这是代码。 I'm positive the error lies within href here. 我很肯定错误位于href此处。

var newTab = $('<li class="nav-item"><a class="nav-link active" id=newTabID data-toggle="tab" href="'#' + albumName" role="tab" aria-controls=albumName aria-selected="true">Album</a></li>');

it should theoretically link to a div with ID albumName 从理论上讲,它应该链接到ID为AlbumNamediv

I know this might sound annoying as it had been asked several times already, but the answers I've found haven't worked for me or is too difficult for me to understand (since question is not exactly alike). 我知道这听起来很烦人,因为已经被问过几次了,但是我发现的答案对我没有用,或者我很难理解(因为问题并不完全相同)。

尝试这个:

var newTab = $('<li class="nav-item"><a class="nav-link active" id=newTabID data-toggle="tab" href="#' + albumName+ '" role="tab" aria-controls=albumName aria-selected="true">Album</a></li>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM