如何向javascript中嵌入的html代码添加html粗体标记?

如何向javascript中嵌入的html代码添加html粗体标记?,javascript,html,Javascript,Html,我在代码中的一些项上放置粗体标记时遇到问题。它将加粗整个单词,包括添加的变量。(我不希望该变量以粗体显示)。谢谢 “”+“鉴于下面列出的更改的严重性,将要求您审查并批准或拒绝此更改。提交人:“+row.requester” +“”+”说明:“+row.comments和正在实施的更改的一般说明和特殊说明 +“”+”报告Id:“+row.rowNumber” 下面是上面代码段的一些附加上下文: function sendReportToManager(row) { var messag

我在代码中的一些项上放置粗体标记时遇到问题。它将加粗整个单词,包括添加的变量。(我不希望该变量以粗体显示)。谢谢

“”+“鉴于下面列出的更改的严重性,将要求您审查并批准或拒绝此更改。提交人:“+row.requester”
+“”+”说明:“+row.comments和正在实施的更改的一般说明和特殊说明
+“”+”报告Id:“+row.rowNumber”
下面是上面代码段的一些附加上下文:

function sendReportToManager(row) { 
    var message = "<HTML><BODY>" + "<p>" +" Given the severity of the change listed below, you are being asked to review and either approve or reject this change. Submitted by: " + row.requester + 
    "<p>" + "<b>Description: </b>" + row.commentsAndGeneralDescriptionOfTheChangeBeingImplementedAndAnySpecialInstructions + 
    "<p>" + "<b>Report Id: </b> " + row.rowNumber + 
    '<p><b>Please approve or reject <A HREF="' + APPROVAL_FORM_URL + '">Change Request</A> #' + row.rowNumber + "</HTML></BODY>";
     MailApp.sendEmail(row.changeManagerApproval, "Change Management Approval - REQUEST", "", {noReply: true, htmlBody: message}); 
} 
函数sendReportToManager(行){
var message=“”+”“+”鉴于下面列出的更改的严重性,将要求您审查并批准或拒绝此更改。提交人:“+row.requester+
“”+”说明:“+row.comments和正在实施的更改的一般说明和特殊说明”
“”+”报告Id:“+row.rowNumber+
“请批准或拒绝“#”+row.rowNumber+”;
MailApp.sendmail(row.changemanageraproval,“变更管理批准-请求”,“,{noReply:true,htmlBody:message});
} 

看起来你有一些不需要的额外东西在里面。试试这个:

"<strong>Given the severity of the change listed below, you are being asked to review and either approve or reject this change.</strong>" + \n  +
"<strong>Submitted by:</strong> " + row.requester +  \n +
"<strong>Description: </strong> "+ row.commentsAndGeneralDescriptionOfTheChangeBeingImplementedAndAnySpecialInstructions +  \n +
"<strong>Report Id:</strong> " + row.rowNumber
鉴于下面列出的更改的严重性,将要求您审查并批准或拒绝此更改。”+\n+
“提交人:”+row.requester+\n+
“说明:”+row.comments和正在实施的更改的一般说明和特殊说明+\n+
“报告Id:”+row.rowNumber
你的例子很有效。您的问题(为什么粗体字没有终止)不能由您提供的信息确定。如果您的变量(例如
行.请求者
)具有打开的
,则它将应用于HTML,直到遇到关闭标记为止

如果您的邮件客户端接受CSS和更好的HTML标记,那么更好的方法就是使用CSS和更好的HTML标记。例如:

"<p>" 
   + "Given the severity of the change listed below, you are being asked to review and either approve or reject this change. "
   + '<span class="label">Submitted by: </span><span class="value">'  
   + row.requester
+ "<p>" 
   + '<span class="label">Description: </span><span class="value">' 
   + row.commentsAndGeneralDescriptionOfTheChangeBeingImplementedAndAnySpecialInstructions
   + "</span>"
+ "<p>" 
   + '<span class="label">Report Id: </span><span class="value">' 
   + row.rowNumber
   + "</span>"


注意:在字符串中嵌入HTML标记还有其他问题,正如您在上面所做的那样-这个答案没有解决这些问题。相反,这个答案应该作为解决问题的第一步。

即使是“考虑到下面列出的更改的严重性…”也适用于我:这个问题的终止粗体标记在哪里<代码>请批准或拒绝?变量注释返回的内容以及正在执行的更改的一般说明和特殊说明?好的,谢谢,我会这样做,并让您知道发生了什么。这个粗体字有什么用?为了可读性,会断行。否则脚本将从屏幕上消失。它对脚本的可用性没有影响,并且修复了他/她的问题,即您可以使用JS中的\n(换行符)转义符在字符串文本中插入新行。这正是我在回答中所说的(使用转义符)。好的,您修复了语法错误。不过,这并不能回答问题。我从来没有出现过任何语法错误。我在回答中解释了该做什么。在我回答之后,OP改变了他的问题的格式。我更新了我的答案以匹配他修改后的问题。
"<p>" 
   + "Given the severity of the change listed below, you are being asked to review and either approve or reject this change. "
   + '<span class="label">Submitted by: </span><span class="value">'  
   + row.requester
+ "<p>" 
   + '<span class="label">Description: </span><span class="value">' 
   + row.commentsAndGeneralDescriptionOfTheChangeBeingImplementedAndAnySpecialInstructions
   + "</span>"
+ "<p>" 
   + '<span class="label">Report Id: </span><span class="value">' 
   + row.rowNumber
   + "</span>"
.label { font-weight: bold; }
.value { font-weight: normal; }