本文介绍了不能使jQ UI手风琴工作w / cookie后jQ / UI升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,使用cookie来使jquery手风琴选择持久性通过刷新



问题是它只适用于jQuery UI 1.7.2和jQuery JavaScript库v1.4.1



如果我更新到jQuery UI - v1.10.0和jQuery JavaScript库v1.9.0,它不会持续了(没有错误,只是在页面加载时不持续手风琴选择)



以下是代码



  $(function()
{
var cookieName ='stickyAccordion';

$('#accordion').accordion({
active: cookies.get(cookieName)|| 0),
change:function(e,ui)
{
$ .cookies.set(cookieName,$(this).find('h3' ).index(ui.newHeader [0]));
}
});
});

在我的HTML中有

 < script type =text / javascriptsrc =jquery.js>< / script> 
< script type =text / javascriptsrc =jquery-ui.js>< / script>
< script type =text / javascriptsrc =jquery.cookies.js>< / script>

Cookie由

解决方案

Cookie代码很好,但是jQuery UI Accordion API随着您的升级而改变,使得更改不再是有效的事件 - 它已更改为 activate 。我们还可以调整 activate 方法的主体,比每次重新查询标题更有效。



以下是正在使用的新API的现场演示:



这里是特定的JS:

  $ function(){
var cookieName ='stickyAccordionNewAPI',
$ accordion = $('#accordion'),
$ headers = $ accordion.children('h3');

$ accordion.accordion({
active:($ .cookies.get(cookieName)|| 0),
activate:function(e,ui){
$。 cookies.set(cookieName,$ headers.index(ui.newHeader));
}
});
});

这并不像UI Tabs所做的那么剧烈的变化,

I have this piece of code, that uses cookies to make jquery accordion selection persist trough refresh

The problem is that it only works with jQuery UI 1.7.2 and jQuery JavaScript Library v1.4.1

If i update to jQuery UI - v1.10.0 and jQuery JavaScript Library v1.9.0, it doesn't persist anymore (no errors, just not persisting accordion selection across page loads)

Here is the code

$( function()
{
    var cookieName = 'stickyAccordion';

    $( '#accordion' ).accordion( {
        active: ( $.cookies.get( cookieName ) || 0 ),
        change: function( e, ui )
        {
    $.cookies.set( cookieName, $( this ).find( 'h3' ).index ( ui.newHeader[0] ) );
        }
    } );
} );

in my html i have

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>
<script type="text/javascript" src="jquery.cookies.js"></script>

cookie is provided by http://code.google.com/p/cookies/

解决方案

The cookie code is fine, but the jQuery UI Accordion API has changed with your upgrade such that change is no longer a valid event--it has been changed to activate. We can also adjust the activate method's body to be more efficient than re-querying for the headers every time.

Here is a live demo of the new API in use: http://jaaulde.com/test_bed/stickyaccordionNewAPI/

And here is the specific JS:

$(function () {
    var cookieName = 'stickyAccordionNewAPI',
        $accordion = $('#accordion'),
        $headers = $accordion.children('h3');

      $accordion.accordion( {
          active: ($.cookies.get(cookieName ) || 0),
          activate: function (e, ui) {
              $.cookies.set(cookieName, $headers.index(ui.newHeader));
          }
      });
});

It's not quite as drastic a change as UI Tabs underwent, but a change nonetheless.

这篇关于不能使jQ UI手风琴工作w / cookie后jQ / UI升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 12:50