[英]JavaScript: Displaying and updating text arrays
尝试使用JavaScript从多个用户指定的变量中将一个段落放到画布上。 我从...开始
function special01() {
//clean slate
ctxx.clearRect(0, 0, ctx.width, ctx.height);
//navigations important
drawNav();
//lets begin
var newSlate = "You're feeling colorChoice today!";
document.getElementById("displayed").innerHTML =
newSlate;
if (user.color == 'blue') {
var array = newSlate.replace("colorChoice", "blue")
}
else if (user.color == 'red') {
etc..etc..
};
}
我似乎忘记了一些东西,而作为一个业余爱好者,我不确定是什么。 基本上我只是想取代colorChoice
与blue
当blue
已经被用户选择。 选择时,所选内容和user.color
正确更新。
你有没有尝试过
function special01(){
ctx.clearRect(0, 0, ctx.width, ctx.height);
drawNav();
document.getElementById('displayed').innerHTML = 'You\'re feeling ' + user.color + ' today!';
}
编辑
如果您确实要替换字符串中的子字符串,则可以这样做
var yourString = 'You\'re feel colorChoice today.';
var user.color = 'blue'; // For example
var newString = yourString.split('colorChoice').join(user.color); // 'You\'re feel blue today.'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.