简体   繁体   中英

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(
    function () {
        $('[data-filter=".music"]').click()
    }
);

Fiddle: http://jsfiddle.net/Lsrvd9et/

[data-filter=".music"] is a selector that selects an element based on an attribute value. And document.ready is an event that runs when the page is ready for JavaScript code to execute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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