最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery append text in but in a new line - Stack Overflow

programmeradmin5浏览0评论

I am trying to append a new line using this this code. I have tried \n and only \ but no solution. What can I do now?

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

I am trying to append a new line using this this code. I have tried \n and only \ but no solution. What can I do now?

function infC(name) {
    jQuery("#dialog").text(information_by_equipment[name][1]).append(information_by_equipment[name][2]);
    event.stopPropagation();
}
Share Improve this question edited Jan 23, 2016 at 20:36 Praveen Kumar Purushothaman 167k27 gold badges213 silver badges259 bronze badges asked Jan 23, 2016 at 20:26 user6135434user6135434 0
Add a ment  | 

3 Answers 3

Reset to default 10

The .append() appends HTML. You need to use <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]);
});

This should solve your problem. Simply add a <br> to enter a new line between your "lines".

If the above solutions are not working try this one.

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

&#10; Line Feed and &#13; Carriage Return

发布评论

评论列表(0)

  1. 暂无评论