0
嘗試使用來自多個用戶指定變量的JavaScript在畫布上放置一個段落。我開始...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..
};
}
我似乎忘記了一些東西,只是一個業餘愛好者,我不知道是什麼。基本上我只是試圖用blue
代替colorChoice
,當用戶選擇blue
時。當選擇時,選擇和user.color
正確更新。
我能做到這一點。然而因爲它將繼續使用取決於選擇哪種顏色的文本,我只是使用if/else來替換句子中的關鍵字。那有意義嗎? – lira153
@ lira153。我編輯了答案。這是你想要的? –