JavaScript 不加载新位置

发布于 2024-10-21 00:53:21 字数 609 浏览 7 评论 0原文

这是我的主要功能,使用jquery和jquery-ui。问题是,它应该在单击链接时加载新地址(在动画“desaparecer”之后)。链接有一个 rel 标签,其中包含“articulo”的编号。

    $(function () {
        function aparecer () {
            $("#centro").show('drop','fast')
        }   
        function desaparecer () {
            $("#centro").hide('drop', 'fast', 'carga ()')
        };
        function cargar () {
            window.location = 'index.php?articulo=' + a.attr('rel');
        };
        $("a").click(function () {
            var a = $(this);
            desaparecer();
            return false;
        });
        aparecer();
    });

This is my main function, using jquery and jquery-ui. The problem is that it should load the new adress when clicking a link (after the animation "desaparecer"). Links have a rel tag which contains the number of the "articulo".

    $(function () {
        function aparecer () {
            $("#centro").show('drop','fast')
        }   
        function desaparecer () {
            $("#centro").hide('drop', 'fast', 'carga ()')
        };
        function cargar () {
            window.location = 'index.php?articulo=' + a.attr('rel');
        };
        $("a").click(function () {
            var a = $(this);
            desaparecer();
            return false;
        });
        aparecer();
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁吢 2024-10-28 00:53:21

carga 不等于 cargar

并且根据 jQuery 文档,回调应该是一个函数,而不是要进行 eval 编辑的字符串。

$("#centro").hide('drop', 'fast', cargar)

carga does not equal cargar

And the callback, according to the jQuery docs, is supposed to be a function, not a string to be evaled.

$("#centro").hide('drop', 'fast', cargar)
情何以堪。 2024-10-28 00:53:21

问题是您已在 标记的点击处理程序中声明了“a”。将其移到这些函数的外部:

$(function () {
    var a;

    function aparecer () {

然后更改点击处理程序:

    $("a").click(function () {
        a = $(this);  // no "var" here
        desaparecer();
        return false;
    });

因为“a”位于点击处理程序内部,所以“cargar”函数看不到它。但是在两个函数之外声明,它们都可以访问相同的变量。

另外,“消失”功能中的“cargar”似乎拼写错误。无论如何,它不应该真正出现在这样的字符串中;它可以看起来像这样:

    function desaparecer () {
        $("#centro").hide('drop', 'fast', cargar)
    };

The problem is that you've declared "a" inside the click handler for the <a> tag(s). Move that out to the outside of those functions:

$(function () {
    var a;

    function aparecer () {

then change the click hander:

    $("a").click(function () {
        a = $(this);  // no "var" here
        desaparecer();
        return false;
    });

Because "a" is inside that click handler, the "cargar" function wouldn't see it. But declared outside both functions, they'll both have access to the same variable.

Also it looks like "cargar" is misspelled in the "disappear" function. It shouldn't really be in a string like that anyway; it can look like this:

    function desaparecer () {
        $("#centro").hide('drop', 'fast', cargar)
    };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文