使用Javascript for HTML使变量大写的第一个字母

问题描述 投票:-2回答:1

我正在尝试使用'innerHTML'打印出我的结果>

  if (userChoice === computerChoice) {
    console.log("Tie!");
    result_h3.innerHTML =
      userChoice + " and " +
      computerChoice +
      " are both the same. It's a draw!";

如何使userChoice变量的首字母在浏览器中大写?

我尝试过:

  if (userChoice === computerChoice) {
    console.log("Tie!");
    result_h3.innerHTML =
      userChoice.value.charAt(0).toUpperCase() +
      userChoice.value.slice(1).toLowerCase() +
      +" and " +
      computerChoice +
      " are both the same. It's a draw!";

没有用。

我正在尝试使用'innerHTML'打印我的结果,如果(userChoice === computerChoice){console.log(“ Tie!”); result_h3.innerHTML = userChoice +“和” + computerChoice + ...

javascript html dom
1个回答
0
投票

这对我有用:

© www.soinside.com 2019 - 2024. All rights reserved.