http://jsfiddle.net/9BCrs/5/链接到外部内容加载到DIV
我有这样的设置使用在左边的DIV两个链接到一个文件加载到一个DIV,但它需要相同的jQuery代码的唯一副本每次有一个新的链接。
有没有办法将被调用的文件和它被调用的DIV通过某种变量连接到链接上,这样代码只能被包含一次?
$(function() {
$(".link1").click(function() {
$(".load_space").load("helloworld.txt", function() {
//Insert contents of file wherever
$(".block1").stop(true, true).animate({ left: -400 }, 200);
$(".block2").stop(true, true).animate({ left: 25 }, 200);
});
});
$(".link2").click(function() {
$(".load_space").load("hellouniverse.txt", function() {
//Insert contents of file wherever
$(".block1").stop(true, true).animate({ left: -400 }, 200);
$(".block2").stop(true, true).animate({ left: 25 }, 200);
});
});
$(".link3").click(function() {
$(".block2").stop(true, true).animate({ left: 450 }, 200);
$(".block1").stop(true, true).animate({ left: 25 }, 200);
});
});
太棒了,我正在使用#2,但我喜欢这两种。很好的帮助。 – Andy 2012-02-07 15:41:23