最近瀏覽記錄

來源:互聯網
上載者:User

 項目中要使用到儲存最近瀏覽的記錄的需求,使用cookie做了一份,備用。

function writeCookie(obj, arylength) {    var history = $.cookie("project_history");//        $.cookie("project_history",null)    var projectId = $("#" + $(obj).prev().attr("id")).val().toLowerCase();    var projectName = $(obj).html().Trim();    if (history != null && history != "undefined") {        var newhistory = "";        var sethistory = "";        var strArray = history.split('|');        //判斷是否存在相同的ID,如果存在,則將點擊的條目放到第一位,否則添加新紀錄        if (history.indexOf(projectId) == -1) {            //判斷數組長度是否小於顯示條數            if (strArray.length > arylength) {                for (var i = arylength; i < strArray.length; i++) {                    //清除多餘的資料,從滿足條數的後一條資料開始移除                    strArray.splice(i);                }                //重新組合歷史資料                for (var m = 0; m < strArray.length; m++) {                    sethistory = sethistory + strArray[m] + "|";                }                sethistory = sethistory.substring(0, sethistory.length - 1);            }            else {                sethistory = history;            }            newhistory = projectId + "#" + projectName + "|" + sethistory;        }        else {            //移除掉點擊的項目            var index = 0;            for (var x = 0; x < strArray.length; x++) {                var equalItem = projectId + "#" + projectName;                if (equalItem == strArray[x]) {                    strArray.splice(x);                    break;                }            }            //重新組合歷史資料            for (var m = 0; m < strArray.length; m++) {                sethistory = sethistory + strArray[m] + "|";            }            sethistory = sethistory.substring(0, sethistory.length - 1);            newhistory = projectId + "#" + projectName + "|" + sethistory;        }        $.cookie("project_history", newhistory);    }    else {        $.cookie("project_history", projectId + "#" + projectName);    }}function createHistoryList(url,container) {    var str = new Array();     var historyList = $.cookie("project_history");    if (historyList != null && historyList != "undefined") {        str = historyList.split('|');        var trHtml = "";        for (var i = 0; i < str.length; i++) {            trHtml += "<tr><td><a href='" + url + str[i].split('#')[0] + "' target='_blank'>" + str[i].split('#')[1] + "</a></td></tr>";        }        var tableHtml = "<table class='grgz_tab001'>" + trHtml + "</table>";        $("#" + container).html(tableHtml);    }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.