我正在尝试使用列表项中的某些字符串替换下划线,但它在列表项的原始文本中没有更改。这是我的代码。
$.each($.parseHTML(customFormSentenceView), function (i, item) {
if ($.parseHTML(customFormSentenceView)[i].outerText.indexOf('_') > -1) {
var startindex = $.parseHTML(customFormSentenceView)[i].outerText.indexOf("_");
var lastindex = $.parseHTML(customFormSentenceView)[i].outerText.lastIndexOf("_");
var len = $.parseHTML(customFormSentenceView)[i].outerText.length;
var initstring = $.parseHTML(customFormSentenceView)[i].outerText.substring(0, startindex);
var endstring = $.parseHTML(customFormSentenceView)[i].outerText.substring(lastindex + 1, len);
$.parseHTML(customFormSentenceView)[i].outerText = initstring + endstring;
}
});
答案 0 :(得分:0)
实际上我必须在循环中更改对象,因为这是原始对象的一部分。
$.each(customFormSentenceView, function (i, item) {
if ($(item).text().indexOf('_') > -1) {
var startindex = $(item).text().indexOf("_");
var lastindex = $(item).text().lastIndexOf("_");
var len = $(item).text().length;
var initstring = $(item).text().substring(0, startindex);
var endstring = $(item).text().substring(lastindex + 1, len);
refinedText += initstring + endstring;
$(item).text(refinedText);
}
});