如何将此链接转换为jquery.load()?

时间:2012-04-16 13:47:04

标签: jquery

我需要将此<a>链接转换为jquery.load() - 如何做到这一点?

这是链接:

<a href="exibelinha.asp?linha=<%= rs_linhas("linha")%>" class="whatever">
    <img src="produtos/linhas/pequeno/<%= rs_linhas("foto_inicial")%>" alt="">
    <h3><%= rs_linhas("linha")%></h3>
</a>

我需要使用这个jQuery脚本来实现它:

$('#exibe_galeria').click(function(e) {
    $('#galeria_oculta').show();
    $('#container').load('exibelinha.asp?xxxx'); //here i need to call the link
    e.preventDefault();
});

在我的负载中,我需要使用此字符串调用另一个页面(exibelinha.asp)?linha=<%= rs_linhas("linha")%>

3 个答案:

答案 0 :(得分:2)

只需停止链接点击事件的默认行为,然后使用您已有的代码。您可能需要在锚点上使用id或类,以便能够创建不会影响页面上其他链接的选择器。像这样:

<强> HTML

<a id="link_exibelinha" href="exibelinha.asp?linha=<%= rs_linhas("linha")%>" class="whatever">
...

<强> JS

$('#link_exibelinha').click(function(e) {
    e.preventDefault();
    var url = this.href;
    $('#galeria_oculta').show();
    $('#container').load(url);
});

答案 1 :(得分:0)

如果我已正确理解您的问题,那么您可以尝试这里。

$('.whatever').click(function(e){
     e.preventDefault();//This will prevent the default behavior of the link
     $('#container').load(this.href);//This will get href from anchor and will load it
});

答案 2 :(得分:0)

$('.whatever').on('click', function(e){
     e.preventDefault();
     $('#container').load(this.href);
});