Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
jQuery使用.not()排除部分内容_Jquery - Fatal编程技术网

jQuery使用.not()排除部分内容

jQuery使用.not()排除部分内容,jquery,Jquery,上面是jQuery的一部分,用于查找类,但不包括.tabs,它是.woocommerce tabs元素的子元素 但是,.tabs仍然显示在输出中,这不是我想要的 示例html输出 .find('.woocommerce-tabs').not('.tabs').html(); 产品说明 健壮的 连续360°转台旋转 补充资料 轮胎(泡沫填充) 16“ 重量(千克) 6950 试试看 .not(':has(.tabs)不选择包含类为tabs的元素的元素您的代码过滤不包含选项卡的元

上面是jQuery的一部分,用于查找类,但不包括
.tabs
,它是
.woocommerce tabs
元素的子元素

但是,
.tabs
仍然显示在输出中,这不是我想要的

示例html输出

.find('.woocommerce-tabs').not('.tabs').html();

产品说明
  • 健壮的
  • 连续360°转台旋转
补充资料 轮胎(泡沫填充) 16“

重量(千克) 6950

试试看


.not(':has(.tabs)
不选择包含类为
tabs的元素的元素

您的代码过滤不包含
选项卡的元素
类名,它不会从html输出中排除指定的元素。您可以
.clone()
元素,删除子体,然后调用
.html()
方法

.find('.woocommerce-tabs').not(':has(.tabs)').html();

一种方法是克隆
.woocommerce选项卡
并从克隆元素中删除
.tabs

.find('.woocommerce-tabs').clone().find('.tabs').remove().end().html();
然后,您可以在代码中使用克隆的
html

var clone = $'.woocommerce-tabs').clone();
clone.find('.tabs').remove();
var html = clone.html();

你可以发布它的html吗?@Joseph添加了html示例
var clone = $'.woocommerce-tabs').clone();
clone.find('.tabs').remove();
var html = clone.html();
.find('.woocommerce-tabs').not('.tabs').html(html);