【问题标题】:IE error on jquery Line 4618jquery 行 4618 上的 IE 错误
【发布时间】:2010-04-27 01:00:21
【问题描述】:

我正在尝试使用下面的 jquery 脚本将一些 css 信息保存到 cookie 中。

对于 Firefox 来说一切都很好,但是 IE 在 jquery Line 4618 上抛出一个错误,每当我包含这个文件时

jQuery(document).ready(function() {

  // cookie period
  var days = 365;

  // load positions and z-index from cookies
  $("div[id*='tqitem']").each( function( index ){
    $(this).css( "left", 
      $.cookie( "im_" + $(this).attr("id") + "_left") );
    $(this).css( "top", 
      $.cookie( "im_" + this.id + "_top") );
     $(this).css( "zIndex", 
      $.cookie( "tqz_" + this.id + "_zIndex") );
  });


  //  bind event
  $(".pagenumbers").draggable({cursor: "move"});
  $("div[id*='tqitem']").bind('dragstop', savePos);
  $("div[id*='tqitem']").bind('dragstop', savePot);


  // save positions into cookies
  function savePos( event, ui ){
    $.cookie("im_" + $(this).attr("id") + "_left", 
      $(this).css("left"), { path: '/', expires: days });
    $.cookie("im_" + this.id + "_top", 
      $(this).css("top"), { path: '/', expires: days });
  $.cookie("im_" + this.id + "_zIndex", 
     $(this).css("zIndex"), { path: '/', expires: days });
  };

var thiss = $("div[id*='tqitem']");

function savePot(){
      $("div[id*='tqitem']").each(function (i) {
          $.cookie("tqz_" + $(this).attr("id") + "_zIndex", 
  $(this).css("zIndex"), { path: '/', expires: days });
      })
};

});



/*ADDITIONAL INFO:

SCRIPT HIERARCHY

Jquery itself
Jquery ui
Jquery cookie plugin
Save cookies js

no matter how i ordered them the result did not change*/

【问题讨论】:

    标签: jquery css user-interface cookies


    【解决方案1】:

    我认为您需要将其余的 this 调用包装在加载和保存部分到 jquery 对象中。您在第一行执行此操作,但在其余部分不执行此操作。例如这段代码:

    // load positions and z-index from cookies
      $("div[id*='tqitem']").each( function( index ){
        $(this).css( "left", 
          $.cookie( "im_" + $(this).attr("id") + "_left") );
        $(this).css( "top", 
          $.cookie( "im_" + this.id + "_top") );
         $(this).css( "zIndex", 
          $.cookie( "tqz_" + this.id + "_zIndex") );
      });
    

    应该是这样的:

    // load positions and z-index from cookies
      $("div[id*='tqitem']").each( function( index ){
        $(this).css( "left", 
          $.cookie( "im_" + $(this).attr("id") + "_left") );
        $(this).css( "top", 
          $.cookie( "im_" + $(this).attr("id") + "_top") );
         $(this).css( "zIndex", 
          $.cookie( "tqz_" + $(this).attr("id") + "_zIndex") );
      });
    

    【讨论】:

    • 我自己解决了这个问题,然后回来回复说已经解决了,但是是的,这就是问题所在,谢谢...在保存时使用 this.id,在加载时使用 attr.id
    【解决方案2】:

    您在实际声明它们之前尝试使用函数savePos 和savePot。如果函数尚不存在,则不能将函数绑定到事件。

    将savePos 和savePot 函数的声明放在您将它们绑定到事件的位置之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-26
      • 2011-10-01
      • 2023-04-01
      • 2011-02-21
      • 2012-08-05
      • 1970-01-01
      • 2010-09-09
      • 2011-11-06
      相关资源
      最近更新 更多