gpt4 book ai didi

javascript - 使用 jquery isotope 时如何自动添加内联样式?如何删除它?

转载 作者:太空宇宙 更新时间:2023-11-04 13:59:33 24 4
gpt4 key购买 nike

我已经搜索过了。我找到了一些链接..但没有一个对我有帮助。

http://stackoverflow.com/questions/13974594/jquery-isotope-plugin-adding-inline-displaynone-cant-figure-out-why
http://stackoverflow.com/questions/10404933/jquery-isotope-library-with-html-tables

<div class="menu filter_open">
<span class="filter_by">
<em>Filter Awards By :</em>
</span>
<span data-filter="country_filter" class="drop-down">
Country
</span>
<span data-filter="continent_filter" class="drop-down">
Continent
</span>
<span data-filter="test_filter" class="drop-down">
Test
</span>
<span data-filter="odi_filter" class="drop-down">
ODI
</span>
<span data-filter="t20_filter" class="drop-down">
T20
</span>
</div>
<div class="filter_open filter_open2">
<div id="country_filter" class="filters">
<p>ghfgh</p>
</div>
<div id="continent_filter" class="filters">
<p>zxzcxzc</p>
</div>
<div id="test_filter" class="filters">
<p>zxczxcz</p>
</div>
<div id="odi_filter" class="filters">
<p>zxczxcxz</p>
</div>
<div id="t20_filter" class="filters">
</div>
</div>

我的 javascript 代码:

 $(document).ready(function(){
var container = $('.filter_open');
$('.filter_open span.drop-down').click(function(){

var selector ='#'+ $(this).attr('data-filter');
container.isotope({
filter: selector
});
return false;
});
});

必要的 CSS 是:

.filter_open2
{

width:100%;
height:4%;
border:1px solid;
}
.filters
{
display:none;
}

.isotope-item {
z-index: 2;
}

.isotope-hidden.isotope-item {
pointer-events: none;
z-index: 1;
}

当我点击 country 时,它应该只显示与 country_filter 匹配的 div 元素。但是当我点击特定的过滤器时,一切都会消失。当我尝试使用 firebug 调试它时,我发现内联样式是自动添加的。为什么它会自动添加?如何解决这个问题呢?你能帮我么?! This is the image before i click on a filter ! This is the picture after i click on country and the below part shows the inline styles that are added automatically

最佳答案

在 jquery isotope 完成向其添加内联样式后,对元素使用 setAttribute("style","");

具有任何 Id 的元素示例:

document.getElementById('#Id').setAttribute("style",""); // For any element Id

See this fiddle 。它只影响内联样式。


更新:

尝试以下代码:

 $(document).ready(function(){
var container = $('.filter_open');
$('.filter_open span.drop-down').click(function(){

var selector ='#'+ $(this).attr('data-filter');
container.isotope({
filter: selector
});

var ele = document.getElementsByClassName("drop-down");

for(i=0;i<ele.length;i++)
{
ele[i].setAttribute("style","");
}
return false;
});
});

Demo Fiddle

关于javascript - 使用 jquery isotope 时如何自动添加内联样式?如何删除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21620090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com