简体   繁体   English

jQuery的JavaScript代码的串联

[英]concatenation of JavaScript code for jQuery append

In the following code some concatenation is needed to put all the lines into PlayersDetail variable so that a div named PlayersList can be appended. 在下面的代码中,需要将所有行放入PlayersDetail变量中,以便可以附加一个名为PlayersList的div。

var onlineStatus="online";
PlayersDetail='Here is some text before if statement.<br>'
if (onlineStatus==="online"){
   'I am online.<br>'
}
'here is some text after if statement.'
$("#PlayersList").append(PlayersDetail);

You need to use concatenation operator 您需要使用串联运算符

var onlineStatus = "online";

PlayersDetail = 'Here is some text before if statement.<br>'
if (onlineStatus === "online") {
    //use concatenation operators
    PlayersDetail += 'I am online.<br>'
    //same as 
   // PlayersDetail = PlayersDetail + 'I am online.<br>'
}
//use concatenation operators
PlayersDetail += 'here is some text after if statement.'

$("#PlayersList").append(PlayersDetail);

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

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