JavaScript 不加载新位置
这是我的主要功能,使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
carga
不等于cargar
并且根据 jQuery 文档,回调应该是一个函数,而不是要进行
eval
编辑的字符串。carga
does not equalcargar
And the callback, according to the jQuery docs, is supposed to be a function, not a string to be
eval
ed.问题是您已在
标记的点击处理程序中声明了“a”。将其移到这些函数的外部:
然后更改点击处理程序:
因为“a”位于点击处理程序内部,所以“cargar”函数看不到它。但是在两个函数之外声明,它们都可以访问相同的变量。
另外,“消失”功能中的“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:then change the click hander:
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: