简体   繁体   中英

How to dynamically change the default values of a jQuery Plugin?

for Example: Go to this page http://www.ndoherty.biz/demos/coda-slider/2.0/ and example number 5.

I would like to change the value of firstPanelToLoad dynamically; say for example: I have four buttons 1,2,3 &4. If a user clicks button number 2, value of firstPanelToLoad should change to 2.

I want something like this: http://jsfiddle.net/Cf47w/1/ when user hit button "Panel4", 4th Panel should be displayed.

I understand that you want to keep your selected panel for later load. You must keep the selected index into Browser Cookies or Keep it on your server. This is sample for using Cookie.

function setCookie(c_name,value,exdays) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
  document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name) {
  var i,x,y,ARRcookies=document.cookie.split(";");
  for (i=0;i<ARRcookies.length;i++) {
    x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
    y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
    x=x.replace(/^\s+|\s+$/g,"");
    if (x==c_name) {
      return unescape(y);
      }
  }
}

$().ready(function() {
  $('#coda-slider-6').codaSlider({
    crossLinking: false,
    firstPanelToLoad: (getCookie('firstPanel') == null ? 3 : getCookie('firstPanel'));
  });
});

// do your code to set cookie when user click on a panel

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