The problem is that an input
cannot have any newline characters in it, so when you assign a string to its .value
, and that string contains newline characters, they just disappear:(问题在于input
中不能包含任何换行符,因此当您将字符串分配给.value
,并且该字符串包含换行符时,它们就会消失:)
input.value = 'foo\nbar'; console.log(input.value.includes('\n'));
<input id="input">
Use a textarea instead:(改用textarea:)
var hiddenInput = document.createElement("textarea");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…