令人困惑我的回答在Dan Def的基础上进行了扩展,提供了一个完整的工作示例和一些额外的解释。不,我愿意接受关于如何实现确认框(特别是在纯JavaScript中)的任何其他建议。它的哪一部分不起作用?有控制台错误吗?如果不需要使用jquery确认插件,只需
令人困惑我的回答在Dan Def的基础上进行了扩展,提供了一个完整的工作示例和一些额外的解释。不,我愿意接受关于如何实现确认框(特别是在纯JavaScript中)的任何其他建议。它的哪一部分不起作用?有控制台错误吗?如果不需要使用jquery确认插件,只需,javascript,jquery,html,confirm,Javascript,Jquery,Html,Confirm,令人困惑我的回答在Dan Def的基础上进行了扩展,提供了一个完整的工作示例和一些额外的解释。不,我愿意接受关于如何实现确认框(特别是在纯JavaScript中)的任何其他建议。它的哪一部分不起作用?有控制台错误吗?如果不需要使用jquery确认插件,只需将click函数中的所有内容替换为If(confirm('you real you want delete!'){//insert delete logic here}没有理由不能在jquery事件处理程序中使用标准javascriptconf
令人困惑我的回答在Dan Def的基础上进行了扩展,提供了一个完整的工作示例和一些额外的解释。不,我愿意接受关于如何实现确认框(特别是在纯JavaScript中)的任何其他建议。它的哪一部分不起作用?有控制台错误吗?如果不需要使用jquery确认插件,只需将click函数中的所有内容替换为
If(confirm('you real you want delete!'){//insert delete logic here}
没有理由不能在jquery事件处理程序中使用标准javascriptconfirm
。如果需要从If
语句中获取单击元素的ID,只需使用this.ID
控制台徽标上无错误即可。这个插件不工作。没有警报框。是的,我以前用过纯JavaScript的方式。只是没那么漂亮。我正在四处寻找其他选项。如果有什么问题的话,我会用纯JavaScript来做。留待以后再说。
<div><a id="1" href="1">1</a></div>
<div><a id="2" href="2">2</a></div>
<div><a id="3" href="2">3</a></div>
$('#1').confirm({
title: 'Confirm!',
content: 'Are you sure you want to delete!',
confirm: function(){
console.log(this.content);
},
cancel: function(){
$.alert('Canceled!')
}
});
<div><a id="1" href="1" onclick="many(this.id)">1</a></div>
<div><a id="2" href="2" onclick="many(this.id)">2</a></div>
<div><a id="3" href="2" onclick="many(this.id)">3</a></div>
function many(id)
{
///ajax call
}
function many(id)
{
$('#'+id).confirm({
title: 'Confirm!',
content: 'Are you sure you want to delete!',
confirm: function(){
console.log(this.content);
},
cancel: function(){
$.alert('Canceled!')
}
});
}
<?php while ($row = $result->fetch()){ ?>
<article id="<?php echo $row['article_id'];?>">
<div class="body>
<h1><?php echo $row['title'];?></h1>
<p><?php echo $row['article'];?></p>
<div><a id="<?php echo $row['article_id'];?>" class="delete">x</a></div>
</div>
</article>
<?php }?>
$('.someClass').click( function(event) {
var ele = $(this).attr('rel');
// ele is the element you clicked on
$.confirm({
title: 'Delete!',
content: 'Are you sure you want to delete!',
confirm: function(){
var dataString = "blogpost="+ele;
$.ajax({
type: "POST",
url: "http://localhost/new12/scripts/delete_blog_ajax.php",
data: dataString,
cache: false,
success: function(html)
{
if(html)
{
$("#aid"+ele).fadeOut('slow', function(){
$(this).remove();
});
return false;
}
}
});
return true;
},
cancel: function(){
$.alert('Canceled!')
}
});
});
$('#1, #2, #3').on('click', confirm);
var confirm = $.confirm({
title: 'Confirm!',
content: 'Are you sure you want to delete!',
confirm: function(){
console.log(this.content);
},
cancel: function(){
$.alert('Canceled!')
}
});
$('#MyContainer').find('a').on('click', confirm)
function confirm(event) {
$.confirm({
title: 'Confirm!',
content: 'Are you sure you want to delete!',
confirm: function(){
console.log(this.content);
},
cancel: function(){
$.alert('Canceled!')
}
});
}
$('a').click(function () {
$(this).confirm({
title: 'Confirm!',
content: 'Are you sure you want to delete!',
confirm: function(){
console.log(this.content);
},
cancel: function(){
$.alert('Canceled!')
}
})
});