简体   繁体   English

HTML 如何将变量作为文本放入段落中?

[英]HTML How do I put my variables into the paragraphs as text?

I have variables labelled $name, $phone, and $totalCost.我有标记为 $name、$phone 和 $totalCost 的变量。 I want to put them into a paragraph, but I'm not sure how to.我想把它们放在一个段落中,但我不知道该怎么做。 Is there a way to break the paragraph just for a few words?有没有办法只用几个词来打破段落?

You can use the paragraph tags around your text:您可以在文本周围使用段落标签:

<p> $name </p>

You did not indicate the contents of the paragraph, so this is just a guess.你没有指明段落的内容,所以这只是一个猜测。

    let str = `We have created a tag for ${$name} with the phone number of ${$phone}.
    The total cost will be: ${$totalCost}.`;

Write the above as a Temperal Literal statement with JS like:将上面的内容写成带有 JS 的 Temperal Literal 语句,例如:

document.getElementById('elemName').innerHTML = str; document.getElementById('elemName').innerHTML = str;

where 'elemName' is the ID value of a paragraph like: <p id='elemName'></p> located somewhere in your HTML page.其中 'elemName' 是段落的 ID 值,例如:<p id='elemName'></p> 位于 HTML 页面的某处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM