English 中文(简体)
jQuery中的.bind()和.ubind()出错
原标题:Messed up with .bind() and .unbind() in jQuery

好的,所以我有两种方法来执行div刷新

$( #player ).load( /videos/index );

在我的rails应用程序中。一个是通过链接

<a href="#" id="nextb" onclick="$( #player ).load( /videos/index ).unbind();">next</a>

other is through shortcut of that button. And they work fine, until i discovered, that if I refresh player twice in a row through the link, and then through the shortcut, it loads div twicely. If i refresh through the link three times in a row, than through the shortcut, than it s loading div three times. And so on.. So, i ve started to trying configure binds (as I assumed, that was the reason), but there were mo result. Here is my messed up in binds shortcut part of application.js

 $(document).ready(function(){;
$(document).bind( keydown ,  space , function() {
    $( #player ).unbind( load );    
    $( #player ).load( /videos/index );
    $(document).unbind();
    }); 
 });

我试图通过快捷方式点击链接,但结果相同,所以我认为问题出在加载中。任何建议都会有所帮助。

最佳回答

避免双重刷新的最佳方法是使用状态标志,指示是否可以再次加载或是否正在加载:

$(document).ready(function() {
    var loading = false;
    function reloadDiv() {
        if(!loading) {
            loading = true;
            $( #player ).load( /videos/index , null, function() { loading = false; });
        }
    }  
    $( #nextb ).click(reloadDiv);
    $(document).bind( keydown ,  space , reloadDiv);
});

祝你好运

问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签