[英]Adding bold text to variable
I am just beginning with JavaScript and what I am trying to achieve now is to add bold style to a variable result. 我只是从JavaScript入手,现在我要实现的目标是为变量结果添加粗体。 The code that I am refering to is the following:
我要引用的代码如下:
if(isNumeric(n)) {
document.write("The square root of " + n + " is " + answer);
}
else {
alert('This is not a number!');
}
I want to make the variable answer
to appear in bold and the result to look like this: 我想使变量
answer
以粗体显示,结果看起来像这样:
Example: The square root of 4 is 2 示例: 4的平方根是2
Thank you all in advance! 谢谢大家!
It's just a matter of adding some HTML ? 这只是添加一些HTML的问题?
if(isNumeric(n)) {
document.write("The square root of " + n + " is <strong>" + answer + "</strong>");
} else {
alert('This is not a number!');
}
This is fine for testing, but in production you wouldn't really use document.write
, and preferably you'd use an external stylesheet and a wrapper element to make parts of the text bold. 这对于测试是很好的选择,但是在生产环境中,您将不会真正使用
document.write
,并且最好使用外部样式表和wrapper元素使文本的部分变为粗体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.