我的AngularJS脚本中有一个ui.bootstrap confirmdlg:
var modalDlgOptions = {
closeButtonText: "No",
actionButtonText: "Yes",
headerText: "my header text",
bodyText: "my body text"
};
confirmDlg.showModal({}, modalDlgOptions).then(function (result) {
// todo something
});
这很好用。但现在我想格式化bodyText。我需要这样的新行:
first line in my body text
second line in my body text
...
last line in my body text
当我使用
时bodyText: "first line in my body text<br>second line in my body text<br>...<br>last line in my body text";
或
bodyText: "first line in my body text<br>second line in my body text<br>...<br>last line in my body text";
我得到了
first line in my body text<br>second line in my body text<br>...<br>last line in my body text
在我的对话框输出中,但不是新行。
是否可以格式化confirmDlg的bodyText以及如何?
感谢您的提示,Thomas
答案 0 :(得分:0)
我找到了这个解决方案:
var modalDlgOptions = {
closeButtonText: "No",
actionButtonText: "Yes",
headerText: "my header text",
bodyText: ""
};
confirmDlg.showModal({}, modalDlgOptions).then(function (result) {
// todo something
});
setTimeout(function() {
var modalBody = document.getElementsByClassName("modal-body");
modalBody[0].innerHTML = "first line in my body text<br />second line in my body text<br /> ... <br />last line in my body text";
}, 100);
感谢评论,托马斯
答案 1 :(得分:0)
改进以前的解决方案:
var waitForElementByClassName = function(element, timeout, callBack) {
window.setTimeout(function(){
if (document.getElementsByClassName(element)[0]){
callBack(document.getElementsByClassName(element)[0]);
} else {
waitForElementByClassName(element, timeout, callBack);
}
}, timeout);
};
waitForElementByClassName("modal-body", 50, function(element) {
element.innerHTML = "first line in my body text<br />second line in my body text<br /> ... <br />last line in my body text";
});