gpt4 book ai didi

jquery - 在新窗口上书写 - 新行丢失

转载 作者:行者123 更新时间:2023-12-01 07:45:10 25 4
gpt4 key购买 nike

<div class="cardtitle">WEB</div>
<textarea id="web">
abc
abc
abc
</textarea>

<div id="btnprint">PRINT</div>

JS

tosend = '';
$('#btnprint').click(function(){
$('.cardtitle').each(function(){
tosend = tosend +
$(this).text().toUpperCase() + '<br>' +
$(this).next().val() +
'<hr>'
});
w=window.open();
w.document.write(tosend);
w.print();
w.close();
});

结果是abc abc abc
而不是:
abc
ABC
abc

新行丢失。

最佳答案

将其包裹在 <pre> 中标签,这样格式就不会丢失。

$('#btnprint').click(function(){
var tosend = '<pre>';
$('.cardtitle').each(function(){
tosend = tosend +
$(this).text().toUpperCase() + '<br>' +
$(this).next().val() +
'<hr>'
});
tosend += '</pre>';
w=window.open();
w.document.write(tosend);
w.print();
w.close();
});

关于jquery - 在新窗口上书写 - 新行丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39555740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com