【问题标题】:How to print text together with variable results [duplicate]如何将文本与可变结果一起打印[重复]
【发布时间】:2019-09-30 17:14:49
【问题描述】:

我做了一个计算器,没问题。它正在显示结果,但我想在结果中添加一个文本。例如:

您在交易中花费“可变结果”美元。

点击计算按钮后会出现结果。我想要这篇文章同样的内容。单击按钮后,所有内容都会一起显示。

我用什么来显示结果

document.querySelector("#example").innerHTML = pri_gra;

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    变量和文本一起打印的方式是这样的:

     console.log("This is the text", variableName);
    

    var b = 30;
    console.log(`This is the text, and ${b} is the variable`);
    

    【讨论】:

      【解决方案2】:

      你可以像下面那样做

      document.querySelector("#example").innerHTML = "You spend " + pri_gra + " dollars in the transaction.";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-18
        • 2015-06-21
        • 2014-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-10
        相关资源
        最近更新 更多