📜  如何在模板文字中包含多行条件 - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:35.204000             🧑  作者: Mango

代码示例1
// example 1
const title = 'title 1';
const html1 = `${title ? `

${title}

` : '

nothing 1

'}` document.getElementById('title-container-1').innerHTML = html1; // example 2 const title2= 'title 2'; const html2 = ` ${title2 ? `

${title2}

` : "

nothing 2

" }` document.getElementById('title-container-2').innerHTML = html2; // example 3 const object = { title: 'title 3' }; const html3 = ` ${(title => { if (title) { return `

${title}

`; } return '

Nothing 3

'; })(object.title) } `; document.getElementById('title-container-3').innerHTML = html3;