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 删除标记内的所有内容,但另一个标记jquery除外_Javascript_Jquery - Fatal编程技术网

Javascript 删除标记内的所有内容,但另一个标记jquery除外

Javascript 删除标记内的所有内容,但另一个标记jquery除外,javascript,jquery,Javascript,Jquery,我有这段html <div id="Cart"> <p> You have <strong>1</strong> item in your cart. Your sub total is <strong>$35.00</strong>. </p> </div> 我需要能够在和之间获取信息并删除所有其他内容,使用jquery可以吗?我尝试

我有这段html

    <div id="Cart">
    <p>
        You have <strong>1</strong> item in your cart.
        Your sub total is <strong>$35.00</strong>.
    </p>
    </div>
我需要能够在和之间获取信息并删除所有其他内容,使用jquery可以吗?我尝试了$Cart strong:没有,但没有选择任何内容,我想可能会将信息放在变量中,删除所有内容。删除并重新打印变量,但我真的不知道该怎么做,有人能帮我吗


强者之间的信息是动态的,我相信所有其他信息都在一个我无法访问的php文件中。。。也许过滤这些词并删除它们?欢迎提供任何建议:

这里有一些代码可以帮助您开始:

var strongs = [];
$('#Cart strong').each(function() {
    strongs.push($(this).text());
});
$('#Cart').html('First strong contains: ' + strongs[0] + '; And the second: ' + strongs[1]);
下面是一个it工作的示例:


好的,如果我明白你想要什么,你想从强者那里得到信息

如果您不反对将类或id添加到strong中,我在这里使用id,这是最好的方法

因此,将您的html更改为:

<div id="Cart">
    <p>
        You have <strong id="numItems">1</strong> item in your cart.
        Your sub total is <strong id="cost">$35.00</strong>.
    </p>
</div>

我不知道你的意思。您希望选择表示购物车中有商品的文本。你的小计是?没有我需要删除的文本。。。然后打印一些类似于第一个strong项目的数据总计:第二个strong的数据您最好将所需内容包装在一个文件中。如中所示:您的购物车中有1个项目。您可以创建一个容器var container=$;,然后从树中移动所有元素:$Cart strong.appendTop;,然后擦除购物车的内容,并附加标签:$cart.html.appendcontainer.children;。OP说“strong”里面的信息是动态的。。。因此,我不是舒尔,如果他能够将id添加到强大的html中,我就不能添加类或编辑html>\u这正是我需要的,非常感谢!我只是想问一个问题,到底是什么?你给我推荐什么好的jquery书吗我只在jquery文档中找到了.pushStack:push是一个本机Javascript函数,它向数组中添加了一个元素。所以[].push3将导致[3]。我认为使用jQuery不需要更多的文档,因为它不是一个很大的库,一定要学习和理解Javascript。我不想在这里为书做广告,但是有很多好的书,而且也没有那么大。
<div id="Cart">
    <p>
        You have <strong id="numItems">1</strong> item in your cart.
        Your sub total is <strong id="cost">$35.00</strong>.
    </p>
</div>
var yourString = "You have " + $('#Cart #numitems').text() + " item(s) in your cart. Your subtotal is: " + $('#Cart #cost').text();