脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-jquery 漂亮的删除确认和提交无刷新删除,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。 本例数据库结构很简单,就一个字段就行了
jquery 漂亮的删除确认和提交无刷新删除
演示
jquery.confirm.js
JavaScript Code
(function($){
$.confirm = function(params){
if($('#confirmOverlay').length){
// A confirm is already shown on the page:
return false;
}
$.each(params.buttons,function(name,obj){
// Generating the markup for the buttons:
buttonHTML += '<a href="#" class="button '+obj['class']+'">'+name+'<span></span></a>';
if(!obj.action){
obj.action = function(){};
}
});
var markup = [
'<p id="confirmOverlay">',
'<p id="confirmBox">',
'<p>',params.message,'</p>',
'<p id="confirmButtons">',
buttonHTML,
'</p></p></p>'
].join('');
$(markup).hide().apPEndTo('body').fadein();
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons,function(name,obj){
buttons.eq(i++).click(function(){
// Calling the action attribute when a
// click occurs, and hiding the confirm.
obj.action();
$.confirm.hide();
return false;
});
});
}
$.confirm.hide = function(){
$('#confirmOverlay').fadeOut(function(){
$(this).remove();
});
}
})(jQuery);
PHP Code
<p id="page">
<?php
require "conn.php";
$SQL="select * From `add_delete_record` where id>0";
$rs=mysql_query($sql);
if ($row = mysql_fetch_array($rs))
{
do {
?>
<p class="item">
<a href="#" >
<?php echo $row['text']?>
</a>
<p class="delete" id="<?php echo $row['id']?>"></p>
</p>
<?php
}
while ($row = MySQL_fetch_array($rs));
}?>
</p>
JavaScript Code
$(document).ready(function(){
$('.item .delete').click(function(){
var elem = $(this).closest('.item');
var id=$(this).attr('id');
$.confirm({
'title' : '删除该记录?',
';message' : '您确认删除该记录? <br />删除后无法恢复记录.',
'buttons' : {
'Yes' : {
'class' : 'blue',
'action': function(){$.ajax({
type: 'GET',
url: 'del.php',
data: 'id='+id,
});
elem.slideUp();
}
},
'No' : {
'class' : 'gray',
'action': function(){} // Nothing to do in this case. You can as well omit the action PRoperty.
}
}
});
});
});
del.php
PHP Code
<?php
require "conn.php";
$id=$_GET['id'];
$delete_small_sql = "delete from add_delete_record where id='$id'";
$result_small = mysql_query($delete_small_sql);
?>
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-jquery 漂亮的删除确认和提交无刷新删除全部内容,希望文章能够帮你解决javascript代码实例教程-jquery 漂亮的删除确认和提交无刷新删除所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。