2011-01-26 35 views
1

請查看:錶行點擊,外部裝載

http://net.tutsplus.com/tutorials/javascript-ajax/how-to-load-in-and-animate-content-with-jquery/

我想要做的是演示版,只使用一個錶行點擊,而不是一個A HREF鏈接的一切。我該怎麼做呢?

EDIT

這是代碼即時試圖使用:

<script> 
$(document).ready(function() { 

    // Check for hash value in URL 
    var hash = window.location.hash.substr(1); 
    var href = $('#MyTable_ID tr td').each(function(){ 
     var href = $(this).attr('href'); 
     if(hash==href.substr(0,href.length-5)){ 
      var toLoad = hash+'.html #DivContent_ID'; 
      $('#DivContent_ID').load(toLoad) 
     } 
    }); 

    $('#MyTable_ID tr td').click(function(){ 

    var toLoad = $(this).attr('rel')+' #DivFromExternalPage'; 
    $('#DivContent_ID').hide('fast',loadContent); 
    $('#load').remove(); 
    $('#wrapper').append('<span id="load">LOADING...</span>'); 
    $('#load').fadeIn('normal'); 
    window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5); 
    function loadContent() { 
     $('#DivContent_ID').load(toLoad,'',showNewContent()) 
    } 
    function showNewContent() { 
     $('#DivContent_ID').show('normal',hideLoader()); 
    } 
    function hideLoader() { 
     $('#load').fadeOut('normal'); 
    } 
    return false; 

    }); 
}); 
</script> 

回答

1

添加的表的ID,諸如ID = '鏈接'

<table id='links'> 
    <tr> 
    <td rel='index.html'>index</td> 

an d然後更改

$('#nav li a').click(function(){ //change the targeted element 
var toLoad = $(this).attr('href')+' #content'; //was the source of the URL we needed 

$('#links tr td').click(function(){ //changed to the td inside a ID'd table 
var toLoad = $(this).attr('rel')+' #content'; //the rel attribute now holds that URL for us... 
+0

打我吧! :) – 2011-01-26 13:16:26