【问题标题】:ASP.NET/jQuery Is it possible to execute a link without opening a new page?ASP.NET/jQuery 是否可以在不打开新页面的情况下执行链接?
【发布时间】:2011-01-12 18:15:33
【问题描述】:

是否可以有一个链接,点击后执行href目标,但不弹出新窗口?

【问题讨论】:

    标签: asp.net jquery html


    【解决方案1】:

    我认为您的意思是使用 jQuery,因为您已将其标记为这样。使用 ajax 调用将点击页面,如果您愿意,您可以在完成时执行操作。 e.preventDefault 将阻止点击(访问 url)发生。

    这样的?

    $("a#mylink").click(function(e){
       var goto = $(this).attr('href'); //get the url
       $.ajax({
          url: goto
       }); //execute the href
       e.preventDefault(); //prevent click
    });
    

    Ajax jQuery reference

    【讨论】:

    • 我是否只是将链接的 ID 设置为 myLink?
    • 您可以这样做,或者对您的页面进行语义化。如果它已经有一个类或 ID,你可以使用它并更改 jQuery。
    猜你喜欢
    • 1970-01-01
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多