我有一个带有textarea的HTML页面,当达到宽度时,该文本区域将文本包装在新行上。
在打印此文本区域时,所有已换行的文本都显示为单行,由于页面的宽度而被截断。
我最好最好只使用javascript / html或css对此进行补救。
我尝试使用javascript
function printTextArea() {
var val1 = document.getElementById("studentname").value;
var val2 = document.getElementById("centernumber").value;
var val3 = document.getElementById("examtitle").value;
if (val1 == "") {
val1 = "Not Set";
}
if (val2 == "") {
val2 = "Not Set";
}
if (val3 == "") {
val3 = "Not Set";
} else {}
childWindow = window.open('','childWindow','location=yes, menubar=yes, toolbar=yes');
childWindow.document.open();
childWindow.document.write('<html><title>'+val1 + " - " + val2 + " - " + val3 + " - " +today+'</title><head></head><body><div><pre>');
childWindow.document.write(document.getElementById('inputText').value.replace(/\n/gi,'<br>'));
childWindow.document.write('</pre></div></body></html>');
childWindow.print();
childWindow.document.close();
childWindow.close();
}
</script>
我尝试将textarea值输出到div甚至是div中的pre标记,但结果始终相同,换行和回车符正确保存