2011-02-15 5 views

답변

1

jquery cookie plugin 쿠키 관리를 단순화 할 수 숨 깁니다. HTML 표시/숨기기에 관해서는 show()hide() 메소드를 살펴보십시오. 정말 내용이/숨기기를 보여줄 필요가있는 경우/이유에 따라

+0

이 쿠키 플러그인 만 사용합니다. –

0

...

은 만약 그렇다면, 당신은 어떻게 사용자 (세션을 식별하는, 특정 사용자에 대한 나타나야는 사용자가 특정 콘텐츠가 , openID)? 이벤트 구동 형입니까? 예를 들어 사용자가 버튼을 클릭하면 콘텐츠가 표시되거나 숨겨지고 쿠키가 표시/숨기기 상태를 저장합니까?

  • 다모
+0

사용자가 버튼을 클릭하면 콘텐츠가 표시되거나 숨겨지고 쿠키가 표시/숨기기 상태를 저장합니까? 클래스가있는 테이블을 숨길 필요가 있습니다 : .panel 또는 클래스가있는 div : #panel images : http://sis.windhover.com/buy/images/btn_show.gif 및 http://companies.elsevierbi.com/ Content/images/btn_hide.gif – user616324

0

당신이 필요로하는 것보다 아마도 더 많은,하지만 난 당신이 얻을 수있는) (.toggle 쿠키와 함께 상태를 저장, 테이블의 섹션을 확장/축소하려면 tablesorter에 플러그인으로 이것을 사용 좋은 효과.

function tableContainer(id,visible,sortColumn,sortOrder){ 
    this.ID = id; 
    this.Visible = visible; 
    this.SortColumn = sortColumn; 
    this.SortOrder = sortOrder; 
} 

function bindTableHeaders(element){ 
    //Bind click handler to the table THs to update object as to current sort column. 
    $("thead th","#" + element).bind("click",function(){ 
    var order = this.order 
    var column = this.column 
    var $table = $(this).closest("table") 
    var visible = $table.attr("expanded") //Technically I suppose if you can click these then it must be visible 
    var id = $table.attr("id") 

    var tableObj = new tableContainer(id,visible,column,order); 

    $.cookie(element, JSON.stringify(tableObj), { secure: true }); //Write the current state into the section cookie 
    }); 
}; 

function recoverState(element) { 
    // pull cookie for page state and visibility 
    var elementData = $.cookie(element); 

    if (elementData != null){ 
    // parse JSON based on object representation 
    var json = JSON.parse(elementData) 
    var id = json.ID; 
    var visible = json.Visible; 
    var sortColumn = json.SortColumn == undefined ? 0 : json.SortColumn 
    var sortOrder = json.SortOrder == undefined ? 0 : json.SortOrder 
    } else { 
    var id = element; 
    var visible = "true" 
    var sortColumn = 0; 
    var sortOrder = 0; 
    } 

    // switch visibility 
    if(visible == "false"){ 
    toggleElement(element) 
    } 

    // Determine if this section has any data (eg. a <tbody>) 
    if ($("tbody","#" + id).length == 0 || $("tbody","#" + id).html() == "") 
    return 

    if (pageAction == "Edit"){ 
     $("#" + id).tablesorter({widgets: ['zebra'], sortList: [[sortColumn,sortOrder]]});  
    } else { 
     $("#" + id) 
     .collapsible("td.collapsible",{ 
        collapse:true 
        }) 
     .tablesorter({widgets: ['zebra'], sortMultiSortKey:'false', sortList: [[sortColumn,sortOrder]]}); 
    } 
} 

function toggleElement(element) { 
if ($("#" + element).attr("expanded") == "true"){ 
    $("#" + element).attr("expanded","false") 
    $("#" + element).hide(); 
    var isVisible = "false" 
} else { 
    $("#" + element).attr("expanded","true") 
    $("#" + element).show(); 
    var isVisible = "true" 
} 

//Rewrite the cookie for this section changing only the visibility 
var elementData = $.cookie(element); 
var visible = isVisible; 
if (elementData != null){ 
    var json = JSON.parse(elementData) 
    var id = json.ID; 
    var sortColumn = json.SortColumn; 
    var sortOrder = json.SortOrder; 
} else { 
    var id = element 
    var sortColumn = 0; 
    var sortOrder = 0; 
} 

var tableObj = new tableContainer(id,visible,sortColumn,sortOrder); 
$.cookie(element, JSON.stringify(tableObj), { secure: true }); //Write the current state into the section cookie 
}