[英]How inline styles are added automatically while using jquery isotope? How to remove it?
我已经搜索过了。 我找到了一些链接..但是它们都没有帮助我。
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调试它时,我发现内联样式会自动添加。为什么会自动添加呢? 如何解决这个问题呢? 你能帮我么?! 这是我单击过滤器之前的图像 ! 这是我单击国家/地区后的图片,下面的部分显示了自动添加的内联样式
使用setAttribute("style","");
在jquery同位素完成向其添加内联样式后的元素上。
具有任何ID的元素的示例:
document.getElementById('#Id').setAttribute("style",""); // For any element Id
请参见此小提琴。它仅影响嵌入式样式。
尝试以下代码:
$(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;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.