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