【问题标题】:cant get the calculator buttons to load无法加载计算器按钮
【发布时间】:2022-01-09 07:49:29
【问题描述】:
function createCalculatorButtons(){
const buttons_row =  6;
let added_buttons= 0;

calculator_buttons.forEach(button =>{
    if(added_buttons % buttons_row == 0){
     input_element.innerHTML += '<div class="row"></div>';
    }
    const row = document.querySelector(".row:last-child");
    row.innerHTML += '<button id = "${button.name}">${button.symbol}</button>';
    added_buttons++;                
})

按钮在那里,但带有 msg ${button.symbol} 而不是实际符号

【问题讨论】:

  • 使用模板文字时,请使用反引号,而不是单/双引号。
  • 谢谢!它现在可以工作了!

标签: javascript html css dom calculator


【解决方案1】:

试图在评论中留下这个,但不知道如何让反引号显示....

使用模板文字时,请使用反引号,而不是单/双引号。

function createCalculatorButtons(){
  ...
  row.innerHTML += `<button id = "${button.name}">${button.symbol}</button>`;
    ...             
})

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-22
  • 2010-11-10
  • 2017-07-12
  • 1970-01-01
  • 1970-01-01
  • 2016-11-24
相关资源
最近更新 更多