2013-06-24 16 views
0

正如您在標題中可以理解的那樣,我希望在字符串操作中使用單引號。這裏是我的代碼:如何在javascript的字符串操作中使用單引號

headline += '<article><h5><a class="headline" onmouseover="headLineDetail(' + this.HeadCaption + ',' + this.ShortDescription + ',' + this.PicUrl + ',' + this.NewsId + ')" href="NewsDetail.aspx?nid=' + this.NewsId + '"' + '">' + this.HeadCaption + this.time + '</a></h5>'; 

我必須給報價給headLineDetail的字符串參數。但我將標題附加到div作爲內部html。我如何在這種情況下使用單引號。

+0

你提的問題是非常不清楚。 – SLaks

回答

4

您可以使用\'來轉義它。

1

只是逃避使用\'

headline += '<article><h5><a class="headline" onmouseover="headLineDetail(\'' + this.HeadCaption + '\',\'' + this.ShortDescription + '\',\'' + this.PicUrl + '\',\'' + this.NewsId + '\')" href="NewsDetail.aspx?nid=' + this.NewsId + '"' + '">' + this.HeadCaption + this.time + '</a></h5>'; 
相關問題