0

我遇到了一个表面上看起来非常容易/尴尬的问题,但我现在不知所措。

这些功能涉及很多背景故事,但我会尽量保持简洁。出于格式化原因,我正在尝试插入回车符/换行符,但它们不起作用,我显然在沮丧中忽略了一些东西。

使用一些用户输入的信息来帮助创建一个应用程序,我有这个功能:

    function insertStaticData(group, title, subtitle, description, content, backgroundImage) {

    var newItem = { group: group, title: title, subtitle: subtitle, description: description, content: content, backgroundImage: backgroundImage };

    list.push(newItem);
}

从而用户输入不同的信息。很容易。最初,内容部分的格式非常难看,因为用户可以输入段落。因为我现在只是在测试,所以我重新格式化了他们的文本,如下所示:

insertStaticData(dataGroups[0], "Administration", "", "",
        "Person's Name \n"
        + "Principal \n"
        + "email@address.com \n\n"
        + "Another Name \n"
        + "Secretary\n"
        + "another.email@address.com", "http://www.imageurls/cf/images/map/map_right.gif");

如图所示,用户没有输入字幕或描述。这很好。但是当我通过 Visual Studio 将此作为 Windows 8 应用程序进行调试时,无法识别行返回。我敢肯定我真的很愚蠢,但是什么给了?希望这不会太令人困惑。

4

1 回答 1

1

As bfavaretto already commented, you need to use <br /> if this is for html.

Better yet, wrap each line in a <p> tag so you can apply CSS-rule(s) if you want to modify appearance without having to change the code:

insertStaticData(dataGroups[0], "Administration", "", "",
    "<p>Person's Name</p>" +
    "<p>Principal</p>" + //etc.

You can make a wrap element to separate the rules like this:

insertStaticData(dataGroups[0], "Administration", "", "",
    "<div class='myClass'>" +
    "<p>Person's Name</p>" +
    //etc...
    + "</div>"

Then in CSS:

.myClass { /* wrapper */ }
.myClass > p { /* per line */ }
于 2013-05-20T22:52:16.260 回答