Javascript 删除/删除“:&引用;HTML页面中的冒号
我无法访问以下HTML,它使用一些外部JS动态显示Javascript 删除/删除“:&引用;HTML页面中的冒号,javascript,jquery,html,Javascript,Jquery,Html,我无法访问以下HTML,它使用一些外部JS动态显示 <td class="quantitybox"> <span class="qty">Quantity</span> <br style="clear:both;"> :<input type="text" value="1" onkeydown="javascript:QtyEnabledAddToCart();" maxlength="8" size="3" na
<td class="quantitybox">
<span class="qty">Quantity</span>
<br style="clear:both;">
:<input type="text" value="1" onkeydown="javascript:QtyEnabledAddToCart();" maxlength="8" size="3" name="QTY.1121309" class="v65-productdetail-cartqty">
</td>
量
:
我希望:在使用Jquery删除/删除之后,但我不知道应该使用什么处理程序。我应该动态地将类应用于
,并以Jquery的方式对其进行处理,而不使用regex
:
$('td.quantitybox').contents().filter(function(){
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
}).remove();
或将textnode更改为空字符串:
$('td.quantitybox').contents().filter(function(){
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
})[0].nodeValue = "";
$('td.quantitybox').contents().filter(function() {
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
}).each(function() {
this.nodeValue = "";
});
$('td.quantitybox').html(function(i, old){
return old.replace(/:\s*</, '<');
});
如果您有多个要删除的带有冒号的文本节点-:
:
$('td.quantitybox').contents().filter(function(){
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
})[0].nodeValue = "";
$('td.quantitybox').contents().filter(function() {
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
}).each(function() {
this.nodeValue = "";
});
$('td.quantitybox').html(function(i, old){
return old.replace(/:\s*</, '<');
});
如果您想使用regex
并意识到它的风险:
$('td.quantitybox').contents().filter(function(){
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
})[0].nodeValue = "";
$('td.quantitybox').contents().filter(function() {
return this.nodeType === 3 && // textNode
$.trim(this.nodeValue) === ":";
}).each(function() {
this.nodeValue = "";
});
$('td.quantitybox').html(function(i, old){
return old.replace(/:\s*</, '<');
});
$('td.quantitybox').html(函数(i,旧){
返回旧的。替换(/:\s*我建议,尽管目前尚未测试,但应执行以下操作:
$('td').each(function() {
var i = this.getElementsByTagName('input'),
text = i.previousSibling.nodeValue.replace(/:/g, '');
i.previousSibling.nodeValue = text;
});
另一个解决方案。例如:
我不明白你的问题,你想要什么?你能看到“:”后面的冒号吗?我想使用JQueryjust do$(“td.quantitybox”).html($(this.html().replace)动态删除它(:@mattytommo。如果要使用html
最好使用接受函数的重载。.html
删除现有元素,因此如果它们有jQuery事件或数据,则会导致bugs@Christoph.谢谢,我也这么认为……:)map
在这里做什么?你想做什么?+1.看起来和你的答案一模一样,但是有了map
,你能给我解释一下他想做什么吗?他所做的显然是想用它来创建一个由元素文本组成的数组。尽管我认为它不起作用,因为(比如filter()
)我认为map()
需要一个返回variableOrExpressionName
语句来填充该数组。