我需要获取href的id,并将其包含在javascript中,但我无法正确理解它。 我想要做的是在delete_page.php获取所选择的ID,所以我可以更新记录使用它,并为此工作,我需要在javascript中delete_page.php显示delete_page.php ?id =(),多数民众赞成我需要做的,如果有人有一个更简单的方法来做到这一点将是伟大的!从href中获取id并将其包含在jquery中
这是我的代码
$(document).ready(function()
{
$('a.delete').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
var id = $(this).parent().parent().attr('id');
var data = 'id=' + id ;
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "delete_page.php?id=",
data: data,
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
});
<a href="#" class="delete" id="post-<?php echo $pid; ?>" name="delete_id">Erase page</a>
我需要从脚本里面的HREF该ID的delete_page.php后?ID =”在这里,任何答案将是十分感谢
我也tryed 删除
$(document).ready(function() {
$('a.delete').click(function (e) {
e.preventDefault();
if (confirm("Are you sure you want to delete this row?")) {
var id = $(this).attr('id').replace(/post-/, ''),
parent = $(this).parent();
$.post("delete_page.php", {
"id": id
})
.done(function (data) {
parent.fadeOut('slow', function() {
$(this).remove();
});
});
}
});
});
但消息后,脚本的其余部分是不工作时,delete_page.php和褪色.. 继承人的小提琴 http://jsfiddle.net/dqn61zgv/
我想要做的是在delete_page.php获取该选择的ID,所以我可以更新记录使用它,并为此工作我需要在JavaScript中的delete_page.php是以显示delete_page.php?id =(),那就是我需要做的,如果有人有一个更简单的方法来做到这一点将是伟大的!
您可能必须阻止锚点的默认操作...也共享相关的html – 2014-09-30 03:46:52
没有必要在'url:“delete_page.php?id =”'so'url中有'id =' :“delete_page.php”然后是'data:{id:id}' – 2014-09-30 03:47:38
什么是父 - >父?我们可以看到你的标记吗? – 2014-09-30 03:47:40