javascript - jquery/javascript 中的换行符

标签 javascript jquery

现在我正在使用 java 脚本、jquery 等。我面临的问题很小。

我正在 CASE block 中写一条文本消息,显示时它是一个长字符串:

Record has been saved successfully Note: If head already exists for the concerned department than your head selection would not have been saved. 

但我想要这样:

Record has been saved successfully 
Note: If head already exists for selected department 
than your head selected would not have been saved.

function ShowMsg() {
        var MessageStatus = $("#HiddenFieldSetMessage").val();
        switch (MessageStatus) {
            case 'SavedButHeadMightExist':
                $("#Msg").text("Record has been saved successfully Note: If head already exists for the concerned department than your head selection would not have been saved");
                $("#ModalHeader").text("Success");
                break;
            case 'NotSaved':
                $("#Msg").text("Record not inserted");
                $("#ModalHeader").text("Error");
                break;
    }
    </script>

最佳答案

你可以使用换行符,但这些并没有真正显示出来,你真正想要的可能只是打破标签

$("#Msg").html("Record has been saved successfully<br />" +
               "Note: If head already exists for the concerned department<br />" +
               "than your head selection would not have been saved");

请注意,您必须将方法从 text() 更改为 html()

关于javascript - jquery/javascript 中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24585273/

相关文章:

jquery - 检查函数是否在 `jQuery` 对象上定义

javascript - 如何在Google Maps中实现Yelp Map Marker/Tooltip Effect?

javascript - 当高度和宽度都需要改变时保持纵横比

javascript - 如何重用方法: define in main object and call from all component in VueJS

php - JavaScript 函数显示 "Uncaught Reference Error"

javascript - 交响乐 1.4 : Call to undefined function visual_effect()

jquery 删除空下拉菜单

javascript - 单击子元素时如何防止模态显示?

javascript - 由于某种原因我无法调用 setup()

javascript - 如何根据 url 添加 "active"类到下拉列表