插入变量作为参数
Insert variable as parameter
我有 Javascript 代码:
document.getElementById("Grid").style.gridTemplateRows = "repeat(3, 2fr)";
当我尝试时,如何插入变量作为参数来修改我的 CSS 样式:
"repeat(${MyVariable}, 2fr)";
好像不行?
${MyVariable}
属于反引号 (template literals)
所以
document.getElementById("Grid").style.gridTemplateRows = "repeat("+MyVariable+", 2fr)";
或
document.getElementById("Grid").style.gridTemplateRows = `repeat(${MyVariable}, 2fr)`;
我有 Javascript 代码:
document.getElementById("Grid").style.gridTemplateRows = "repeat(3, 2fr)";
当我尝试时,如何插入变量作为参数来修改我的 CSS 样式:
"repeat(${MyVariable}, 2fr)";
好像不行?
${MyVariable}
属于反引号 (template literals)
所以
document.getElementById("Grid").style.gridTemplateRows = "repeat("+MyVariable+", 2fr)";
或
document.getElementById("Grid").style.gridTemplateRows = `repeat(${MyVariable}, 2fr)`;