在JavaScript中,换行符实际上并不是在创建新行,有没有其他选择,或者我做错了什么

In JavaScript the newline character is not actually creating a new line, is there an alternative or am I doing something wrong?

本文关键字:或者 选择 什么 错了 其他 新行 JavaScript 换行符 实际上 创建 并不是      更新时间:2023-09-26

我正在尝试创建一个将输出XSL文件的程序。下面是我尝试使用的代码。"''n"实际上并没有创建新行,下一个值放在它旁边。我做错了什么吗?

var TheTextBox = document.getElementById("output");
        countOfAdd += 1;
        if (countOfAdd > 1){
            TheTextBox = "";
            countOfAdd = 1;
        }
        else if (countOfAdd == 1){
            //where all of the xsl output will be
            //line 1
            TheTextBox.value = TheTextBox.value + '<?xml version="1.0"?>' + ''n';
            //line 2
            TheTextBox.value = TheTextBox.value + '<!-- Sets up the stylesheet and declares the :xfa function in case you want to globalize fields -->';

编辑:我已经尝试过br HTML字段,但由于这是一个文本框,我添加到其中只是将其包含在输出中

编辑2:我的例子已经不起作用了。不确定原因,但文本字段完全忽略了。

放弃并将其更改为文本区域,而不是输入文本字段。。我的错误。现在有效,谢谢大家。

我看到你可能把它放在了一个文本字段中。

如果是这种情况,请尝试

&#13;&#10;

它应该在文本字段中工作。

点击此处查看答案。

您需要使用HTML实体&#13;&#10;。它们创建新行,而不是显示'n字符。