2013-03-26 26 views
0

我已經看了所有,似乎只能找到更多的靜態版本(爲缺乏更好的詞)可以通過AJAX調用哪些URL/jQuery的要求:檢測哪個URL從onclick通過AJAX/Jquery加載適當的內容

的Jquery:

$(document.body).ready(function() { 
    $("li.span3 a").click(function (e) { 
     $('.content').load(this.href); 
     e.preventDefault(); 
      }); 
     }); 

HTML/PHP:

while ($loop->have_posts()) : $loop->the_post(); 
    echo 
    '<li class="span3 mobile_width"><a href="http://localhost/sites/wp-osprey/?team=jo-bloggs2">'; 

     the_content(); 
     the_title(); 
     echo '</a></li>'; 
    endwhile; 

我想它是一個變量,因此它可以聽出了其中的div被點擊後顯示對應g外部html作爲onclick div在while循環中。

我需要在onclick上創建並添加監聽事件,以便抓取正確的外部URL或者是否有其他方法來編寫上述內容?

回答

1

這是最正確的。要從href獲取URL,您必須改用$(this).attr('href')。這已經將onclick事件綁定到所有「li.span3 a」元素上。

0

據我所知,您試圖獲得<a>標記中被點擊的href屬性的值。

$(document.body).ready(function() { 
    $("li.span3 a").click(function (e) { 
     var thisURL = $(this).attr("href"); 
     e.preventDefault(); 
    }); 
});