gpt4 book ai didi

javascript - 用于 jQuery append 的 JavaScript 代码串联

转载 作者:行者123 更新时间:2023-12-03 12:31:39 25 4
gpt4 key购买 nike

在以下代码中,需要进行一些串联以将所有行放入 PlayersDetail 变量中,以便可以 append 名为 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);

最佳答案

您需要使用串联运算符

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);

关于javascript - 用于 jQuery append 的 JavaScript 代码串联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23902240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com