简体   繁体   English

页面加载时如何应用过滤器?

[英]How to apply filter when page load?

Filters have this code: 过滤器具有以下代码:

<li style="float:left; width:70px; padding-left: 10px;"><a href="#none" data-filter=".film"><img src="img/study.png" width="70"></a></li>
<li style="float:left; width:70px; padding-left: 10px;"><a href="#none" data-filter=".music"><img src="img/study.png" width="70"></a></li>
<li style="float:left; width:70px; padding-left: 10px;"><a href="#none" data-filter=".art"><img src="img/study.png" width="70"></a></li>

I want to create an autoload for a filter when starting the page. 我想在启动页面时为过滤器创建自动加载。 The main in the filter is: 过滤器中的主要内容是:

data-filter=".music"

But I dont know automatically call this filter when starting the page. 但是我不知道在启动页面时会自动调用此过滤器。 How do I do that? 我怎么做?

You can do it on $(document).ready() . 您可以在$(document).ready()

$(document).ready(
    function () {
        $('[data-filter=".music"]').click()
    }
);

Fiddle: http://jsfiddle.net/Lsrvd9et/ 小提琴: http : //jsfiddle.net/Lsrvd9et/

[data-filter=".music"] is a selector that selects an element based on an attribute value. [data-filter=".music"]是用于基于属性值选择元素的选择器。 And document.ready is an event that runs when the page is ready for JavaScript code to execute. document.ready是页面准备好执行JavaScript代码时运行的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM