我有类似的东西
最佳答案
这样更有效,因为它只选择具有data-count属性的div,并且只为每个元素构造一次jQuery对象:
$('div[data-count]').each(function () {
var $this = $(this);
if ($this.attr('data-count') < 15) {
$this.remove();
}
});
演示:
$('button').on('click',function () {
$('div[data-count]').each(function () {
var $this = $(this);
if ($this.attr('data-count') < 15) {
$this.remove();
}
});
});
div[data-count]:before {
content: "
本机JavaScript中的替代解决方案:
var divs = document.querySelectorAll('div[data-count]'),div,i;
for (i = 0; i < divs.length; i++) {
div = divs[i];
if (div.getAttribute('data-count') < 15) {
// this will not affect iteration because querySelectorAll is a non-live NodeList
div.parentNode.removeChild(div);
}
}
演示:
var button = document.querySelector('button');
button.addEventListener('click',function () {
var divs = document.querySelectorAll('div[data-count]'),i;
for (i = 0; i < divs.length; i++) {
div = divs[i];
if (div.getAttribute('data-count') < 15) {
// this will not affect iteration because querySelectorAll is a non-live NodeList
div.parentNode.removeChild(div);
}
}
});
div[data-count]:before {
content: "
相关文章
准备:导入ElementUI 看官网教程 数据准备:JSON数据转换成树状...
vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些