嗨,我是 jquery 的新手...
我的项目中很少有 anchor 链接...
<a href="#" id="1" class="delete" onclick="dele()"> Remove1 </a>
<a href="#" id="2" class="delete" onclick="dele()"> Remove2 </a>
<a href="#" id="3" class="delete" onclick="dele()"> Remove3 </a>
<a href="#" id="4" class="delete" onclick="dele()"> Remove4 </a>
function dele()
{
fid= //here i want id of that element which called it
$.ajax({
url : 'ajax.php',
data : {delet:'delet',fid:fid},
type : 'POST',
success : function(data)
{
$("#showform").html(data);
alert(data);
}
});
}
例如
如果我点击 Remove1 然后我希望它的 id 说 1,
如果我点击 Remove2 然后我希望它的 id 说 2 等等......
我尝试通过 $(".delete").click() 来做到这一点,但我无法使用它,因为它给我的项目带来了问题...
这里是我通过数据库生成的id...
你能建议我如何获得 ID 吗???
提前致谢..
最佳答案
试试这个
<a href="#" id="1" class="delete" onclick="dele(this.id)"> Remove1 </a>
脚本
function dele(id)
{
fid= id //here your id
$.ajax({
url : 'ajax.php',
data : {delet:'delet',fid:fid},
type : 'POST',
success : function(data)
{
$("#showform").html(data);
alert(data);
}
});
}
关于javascript - 如何获取调用函数的元素的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19977511/