Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除/删除“:&引用;HTML页面中的冒号_Javascript_Jquery_Html - Fatal编程技术网

Javascript 删除/删除“:&引用;HTML页面中的冒号

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

我无法访问以下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" 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
语句来填充该数组。