我从html文件中获取一些文本并将其分配给变量。我想解析这个变量的文本:" AB"并在每个实例后插入换行符。
$(flyout).click(function () {
WinJS.xhr({ url: "http://somesite.html", responseType: "text" })
.done(function complete(result) {
var rawText = result.responseText;
var endResult = $(rawText).text();
//need to parse endResult and add 2 line breaks and display in div fetchedtext
fetchedtext.innerText = ParsedendResult;
答案 0 :(得分:1)
var endResult = $(rawText).text();
endResult = endResult.replace(/AB/g, "AB<br>");
更多信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace