我使用的JavaScript工具提示構造函數允許HTML作爲其內容的一部分。我想寫一個幫助函數返回一個代表HTML的對象(因爲確切的HTML將取決於構造函數的輸入參數)。我怎樣才能做到這一點? (僞碼是這樣的:使用Javascript創建和傳遞HTML
function makeHTML(data1, data2){
var HTML = ""
if (property holds){
add the following to the HTML:
"<br>" +
"<b>" + "Constant " + "</b>" + "<br>" +
"<b>" + varibale + "! " + "</b>" + moredata1 +
"<br>"
}
if (another property holds){
add the following to the HTML:
"<br>" +
"<b>" + "Constant2 " + "</b>" + "<br>" +
"<b>" + varibale2 + "! " + "</b>" + moredata2 +
"<br>"
}
)。我遇到了一些試圖返回標籤和報價的問題。
當我填充工具提示沒有動態創建HTML內容,正確的格式在引號標記(如「 」):
return {
title: information
content:
"<br>" +
data[9] + variable + "<br>"
} 現在,我希望讓這個迴歸之前,我可以打電話makeHTML寫:
var dynamicHTML = makeHTML(data1, data2)
return {
title: information
content: dynamicHTML
}
你爲什麼不只是HTML存儲在任何一個數據 - 屬性,或者在兄弟節點你的HTML(隱藏)。這樣工具提示和需要工具提示的東西就在一起。 –