簡體   English   中英

jQuery 在新行中附加文本

[英]jQuery append text in but in a new line

我正在嘗試使用此代碼添加一個新行。 我試過 \n 並且只試過 \ 但沒有解決方案。 我現在能做什么?

function infC(name) {
    jQuery("#dialog").text(information_by_equipment[name][1]).append(information_by_equipment[name][2]);
    event.stopPropagation();
}

.append()附加 HTML。 你需要使用<br />

jQuery("#dialog")
  .text(information_by_equipment[name][1])
  .append("<br />" + information_by_equipment[name][2]);
$(document).ready(function(){
    $("#dialog").append((information_by_equipment[name][1] + "<br>" + information_by_equipment[name][2]);
});

這應該可以解決您的問題。 只需添加一個<br>即可在您的“行”之間輸入一個新行。

如果上述解決方案不起作用,請嘗試這個。

jQuery("#dialog")
  .text(information_by_equipment[name][1])
  .append("&#13;&#10;" + information_by_equipment[name][2]);

&#10; 換行和&#13; 回車

暫無
暫無

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

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