这一个让我难住。我想从label
元素中删除“+”。这里的HTML:从字符串中移除一个字符:不移除内部元素
<label class="option" for="edit-attributes-21-33">
<input type="radio" id="edit-attributes-21-33" name="attributes[21]"
value="33" checked="checked" class="form-radio"> 4 oz, +$15.00</label>
我开始用这个
$(".option").each(function(index, value) {
$(this).text($(this).text().replace("+", ""));
})
这消除了 “+”,而且还剔除了input元素。于是我尝试:
$(".option").each(function(index, value) {
var oldString = $(this).html();
var newString = oldString.replace("+", "");
console.log(oldString, newString);
$(this).text(newString);
})
这使得正确的HTML标记的字符串,但它是一个字符串,并传回给DOM的方式。我看到另一篇文章有同样的问题,但没有解决方案。
相关但不完全重复:http://stackoverflow.com/questions/4106809/how-can-i-change-an-elements-text-without-changing-its-child -lelements –
我不确定输入元素的含义是否被删除?给出一个例子,说明它最初是什么,在当前代码之后它变成了什么,以及你希望它做什么。 EX:原文:'Abc + 123 + 456'应该是'Abc 123 + 456',但这段代码返回'Abc 123 456' – Nitroware