English 中文(简体)
继承法
原标题:Sequenced jQuery code
  • 时间:2011-06-24 07:32:31
  •  标签:
  • jquery

如何顺序排列以下的法典,这样一行在以前的之后?

$( #jqNav li a ).click(function(e){

    if($(this).parent().is(".nav1")){ $( .landing .main .nav ul ).css({ "background-position" : "0 -50px" });} 
    else if($(this).parent().is(".nav2")) { $( .landing .main .nav ul ).css({ "background-position" : "0 -100px" });}
    else if($(this).parent().is(".nav3")) { $( .landing .main .nav ul ).css({ "background-position" : "0 -150px" });}
    else if($(this).parent().is(".nav4")) { $( .landing .main .nav ul ).css({ "background-position" : "0 -200px" });};

    stopAnim = true;
    $page = $(this).attr( href );
    var $hashTag = $(this).attr( name );
    window.location.hash = $hashTag;
    loadData();
    $(window).scrollTop(0);
    e.preventDefault();

});
最佳回答

I would already bind the ajax call inside of the loadData block to a method on success. I have fabricated and tested (FF 5.0 & IE 9) the following code snippet and the success method is called (you need to create the test.html file):

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script>
$(function()
{
    $( a ).click(function()
    {
        loadData();
        return false;
    });

    function loadData()
    {
        $.ajax({
          url: "test.html",
          context: document.body,
          success: loadDataSuccess()
        });
    }

    function loadDataSuccess()
    {
        alert( success! );
        $(window).scrollTop(0);
    }
});
</script>
</head>
<body>
<a href="bla.html">Test</a>
</body>
</html>

我注意到的唯一一点是,即假冒不会阻止我跟踪这一联系,这样我就改变了这种联系,以换取虚假的回报。

问题回答

假设loadData()正在引起日本宇宙航空研究开发机构的一致要求,你的问题只是如何推迟最后一点:

$(window).scrollTop(0)

until after the new content is loaded.

The best way to handle that will be for loadData() to return a handle to the AJAX request, and then use:

loadData().done(function() {
    $(window).scrollTop(0);
});

采用Kil Query1.5中引入的推迟目标提要

You should check out .queue() if you re looking to do animations.

rel=“nofollow”>http://api.jquery.com/queue/

从我的理解来看,你为取得成功而重新尝试这样做?

        $( #jqNav li a ).click(function (e) {
    if ($(this).parent().is(".nav1")) {
            $( .landing .main .nav ul ).css({
                    "background-position": "0 -50px"
            });
    }
    else if ($(this).parent().is(".nav2")) {
            $( .landing .main .nav ul ).css({
                    "background-position": "0 -100px"
            });
    }
    else if (
    $(this).parent().is(".nav3")) {
            $( .landing .main .nav ul ).css({
                    "background-position": "0 -150px"
            });
    }
    else if ($(this).parent().is(".nav4")) {
            $( .landing .main .nav ul ).css({
                    "background-position": "0 -200px"
            });
    };
    e.preventDefault();
    stopAnim = true;
    $page = $(this).attr( href );
    var $hashTag = $(this).attr( name );
    window.location.hash = $hashTag;
    $.ajax({
            url: $(this).attr( href ),
            success: function (e) {
                    $(window).scrollTop(0);
                    // Run your scripts to occur after ajax success in here
            },
            error: function (e) {
                    console.log( error occured );
            }
    });

});





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签