0

我刚刚从jquery-1.6.1.min.jsto更新了我的 jQuery jquery-1.8.2.js,现在这段代码不再起作用了:

<script type='text/javascript'>
$(window).load(function(){
    $('.freezebg').click(function() {
        var ftop = $('.sort-wrap').offset().top - $(window).scrollTop();
        var fleft = $('.sort-wrap').offset().left;
        $('.sort-wrap').css({position: 'fixed', left: fleft + 'px', top: ftop + 'px'});
});
$(".unfreezebg").click(function() {
    $('.sort-wrap').css({position: 'absolute',left:'auto',top: 'auto'});
        return false;
    });
});
</script>

<script type='text/javascript'>
$(document).ready(function() {
    $("#cboxOverlay").addClass("unfreezebg");
});
</script>

有谁知道为什么?

4

2 回答 2

0

try.on('load', handler)因为.load()在 1.8 中已弃用。

<script type='text/javascript'>
   $(window).on('load',function(){
    $('.freezebg').click(function() {    
      var ftop = $('.sort-wrap').offset().top - $(window).scrollTop();
      var fleft = $('.sort-wrap').offset().left;
      $('.sort-wrap').css({position: 'fixed', left: fleft + 'px', top: ftop + 'px'});
    });
    $(".unfreezebg").click(function() {
      $('.sort-wrap').css({position: 'absolute',left:'auto',top: 'auto'});   
      return false;   
    });
   });
</script>
于 2013-01-18T16:24:37.227 回答
0

.on是“新方式”:

<script type='text/javascript'>
   $(window).on('load',function(){
    $('.freezebg').on('click', function() {    
      var ftop = $('.sort-wrap').offset().top - $(window).scrollTop();
      var fleft = $('.sort-wrap').offset().left;
      $('.sort-wrap').css({position: 'fixed', left: fleft + 'px', top: ftop + 'px'});
    });
    $(".unfreezebg").on('click', function() {
      $('.sort-wrap').css({position: 'absolute',left:'auto',top: 'auto'});   
      return false;   
    });
   });
</script>

.on.click(...现在是标准,您应该开始使用它,因为它既可以.live('click'...

于 2013-01-18T16:35:25.377 回答