在使用window.name刷新浏览器后,如何在不使用cookie的情况下保留菜单按钮

时间:2015-07-15 14:46:26

标签: javascript jquery html css cookies

我阅读了关于window.name的文章,但我无法将其改编为我的代码。也许你可以帮助我。 (my website

按照相关性排序菜单时排序'然后转到某个项目,浏览器刷新,排序又回到了“日期”状态。试。

有没有办法可以节省'当时的排序,一个人没有cookie访问我的网站?也许用window.name?



/** 
 * Hier beginnt im JSFiddle der JavaScript Bereich
 *
 * @param sortCriteria
 *   Name of the data-attribute for sorting.
 * @param itemsToSort
 *   A string selector for items for sorting.
 * @param container
 *   A container to put items.
 * @returns {Function}
 */
var sortByDataAttr = function (sortCriteria, itemsToSort, container) {
    return function () {

        // Grab all the items for sorting.
        var $collection = $(itemsToSort);

        // Sort them and append in to container.
        $collection.sort(function (a, b) {
            return $(b).data(sortCriteria) - $(a).data(sortCriteria)
        }).appendTo($(container));
    };
},


/**
 * Remove class from all elements and apply to current.
 *
 * @param current
 *   HTML node to apply class.
 * @param activeClass
 *   Active-state string class.
 */
highlightActive = function (current, activeClass) {
    $('.' + activeClass).removeClass(activeClass);
    $(current).addClass(activeClass);
};

// Sort by 'data-date' at the start.
highlightActive('.btn-sort-date', 'btn-sort--active');
sortByDataAttr('date', '.item', '.list');

$('.btn-sort-date').on('click', function () {
    highlightActive(this, 'btn-sort--active');
    sortByDataAttr('date', '.item', '.list')();
});

$('.btn-sort-relevance').on('click', function () {
    highlightActive(this, 'btn-sort--active');
    sortByDataAttr('relevance', '.item', '.list')();
});
// Hier endet im JSFiddle der JavaScript Bereich

div.daterel(stackoverflow){
    position: relative;
    right: 110px;
top: 20px;

}

<!-- Im JSFiddle startet der html Bereich hier -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<aside id="nav_menu-5" class="widget-1 widget-first widget-odd widget widget_nav_menu">
    <div class="menu-projects-container">
        <ul id="menu-projects" class="menu">

<div style="color:#A4A4A4" class="daterel"> 
<span class="btn btn-sort-date"><i>date</i></span>
<span>|</span>

                <span class="btn btn-sort-relevance"><i>relevance</i></span>
</div>

            <div class="projects">


<b>PROJECTS</b>

           
            </div>
            <div class="list">
                     <li id="menu-item-649" class="item" data-relevance="11" data-date="2015.6"><a href="http://thomasmedicus.at/brickstone-blues/">brickstone blues</a>
                         
                <li id="menu-item-649" class="item" data-relevance="7" data-date="2015.5"><a href="http://thomasmedicus.at/copypaste/">copy&#038;paste</a>

                    <li id="menu-item-649" class="item" data-relevance="6" data-date="2015.4"><a href="http://thomasmedicus.at/zebral-fluids/">zebral fluids</a>

                        <li id="menu-item-649" class="item" data-relevance="8" data-date="2015.3"><a href="http://thomasmedicus.at/fried-egg-variation/">fried egg variation</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="8" data-date="2015.2"><a href="http://thomasmedicus.at/bearrr/">bearrr&#8230;</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="7" data-date="2015.1"><a href="http://thomasmedicus.at/glass-ribbon/">glass ribbon</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="13" data-date="2014.5"><a href="http://thomasmedicus.at/emulsifier/">emulsifier</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="9" data-date="2014.4"><a href="http://thomasmedicus.at/black-holes/">black holes</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="7" data-date="2014.3"><a href="http://thomasmedicus.at/this/">**** this!</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="10" data-date="2014.2"><a href="http://thomasmedicus.at/heads/">heads</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="6" data-date="2014.1"><a href="http://thomasmedicus.at/staining-glass/">staining glass</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="11" data-date="2013.2"><a href="http://thomasmedicus.at/fishbird/">fish&#038;bird</a>

                        </li>
                        <li id="menu-item-649" class="item" data-relevance="5" data-date="2013.1"><a href="http://thomasmedicus.at/faces/">faces</a>

                        </li>
            </div>
<!-- Im JSFiddle geht der html Bereich bis hier -->
&#13;
&#13;
&#13;

感谢您的帮助!

0 个答案:

没有答案