簡體   English   中英

向變量添加粗體

[英]Adding bold text to variable

我只是從JavaScript入手,現在我要實現的目標是為變量結果添加粗體。 我要引用的代碼如下:

if(isNumeric(n)) { 
    document.write("The square root of " + n + " is " + answer); 
} 
else { 
    alert('This is not a number!');
}

我想使變量answer以粗體顯示,結果看起來像這樣:

示例: 4的平方根是2

謝謝大家!

這只是添加一些HTML的問題?

if(isNumeric(n)) { 
    document.write("The square root of " + n + " is <strong>" + answer + "</strong>"); 
} else { 
    alert('This is not a number!');
}

這對於測試是很好的選擇,但是在生產環境中,您將不會真正使用document.write ,並且最好使用外部樣式表和wrapper元素使文本的部分變為粗體。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM