0

我已经看了一遍,似乎只能找到更多静态版本(因为缺少更好的词)可以在 AJAX / Jquery 请求中调用哪些 URL:

查询:

 $(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,然后在 onclick div 处于 while 循环中时显示相应的外部 html。

我是否需要在 onclick 上创建和添加监听事件,以便它可以获取正确的外部 URL,或者是否有不同的方法来编写上述内容?

4

2 回答 2

1

这大多是正确的。要从 a href 获取 URL,您必须使用 $(this).attr('href') 代替。这已经将 onclick 事件绑定到所有“li.span3 a”元素上。

于 2013-03-26T18:32:58.127 回答
0

据我了解,您正在尝试获取单击的标签中的href属性值。<a>

$(document.body).ready(function () {
    $("li.span3 a").click(function (e) {
        var thisURL = $(this).attr("href");
        e.preventDefault();
    });
});
于 2013-03-26T18:33:13.500 回答