使用Jquery传递参数链接 [英] Passing link with parameters with Jquery

查看:74
本文介绍了使用Jquery传递参数链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此链接:

<a id='delete' href='/add/delete.php?iid=XXXXX'>#</a>

我想通过Jquery传递它,以便页面不会刷新.但是,我很难做到这一点.我尝试使用Jquery进行的所有点击事件和Ajax均未成功.

And I want to pass it on through Jquery so the page doesn't refresh. However, I'm having a difficult time making that happen. All of the click events and ajax I've tried with Jquery have been unsuccessful.

基本上,我希望ajax向delete.php发送iid参数中的值.

Basically, I want the ajax to send delete.php the value in the iid parameter.

推荐答案

在此尝试href='1'是您要删除的ID,也替换它找到id="d1"的文本:

Here try this the href='1' is the id you want to delete, also to replace the text it finds the id="d1":

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
  $(".delete").click(function(e){
    var del_id = $(this).attr('href');
    e.preventDefault();
    $.post("/add/delete.php", { iid: del_id } ,function(data){
        //change the link to deleted
        $('#d'+del_id).replaceWith('<a href="#">Deleted</a>');
    });
  });
});

</script>
</head>
<body>
 <a class='delete' id="d1" href='1'>Delete</a>
 <a class='delete' id="d2" href='2'>Delete</a>
 <a class='delete' id="d3" href='3'>Delete</a>
 <a class='delete' id="d4" href='4'>Delete</a>
</body>
</html>

这篇关于使用Jquery传递参数链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆