0

我有一个用于确认删除的脚本...

$('document').ready(function(){
     $('.ask').jConfirmAction();
});

产品列表如下

<?php if(isset($query)){ ?>        
<input disabled type="hidden" id="recNum" value="<?php echo $rec ?>"/>
<table id="rounded-corner" summary="2007 Major IT Companies' Profit" width="100%">
    <thead>
        <tr>
            <th scope="col" class="rounded-company"></th>
            <th scope="col" class="rounded">Product ID</th>
            <th scope="col" class="rounded">Product Name</th>
            <th scope="col" class="rounded">Product slug</th>
            <th scope="col" class="rounded">Type</th>
            <th scope="col" class="rounded">Product Category</th>
            <th scope="col" class="rounded">Edit</th>
            <th scope="col" class="rounded-q4">Delete</th>
        </tr>
    </thead>
        <tfoot>
        <tr>
            <td colspan="7" class="rounded-foot-left"><em>All The Pages That Being Included</em></td>
            <td class="rounded-foot-right">&nbsp;</td>

        </tr>
    </tfoot>
    <tbody>
         <?php
     foreach($query as $key => $row) {
    ?> 
        <tr>
            <td><input type="checkbox" name="" /></td>
            <td><?php echo $row['product_id'];?></td>
            <td><?php echo $row['product_name'];?></td>
            <td><?php echo $row['product_slug'];?></td>
            <td><?php echo $row['type'];?></td>
            <td><img src="<?php echo base_url().$row['product_image'];?>" width="80px" height="80px"/></td>
            <td><a href="<?php echo base_url();?>admin.php/products/edit_product/<?php echo $row['product_id'];?>"><img src="<?php echo base_url();?>assets/admin_assets/images/user_edit.png" alt="" title="" border="0" /></a></td>
            <td><a href="<?php echo base_url();?>admin.php/products/delete_product/<?php echo $row['product_id'];?>" class="ask"><img src="<?php echo base_url();?>assets/admin_assets/images/trash.png" alt="" title="" border="0" /></a></td>
        </tr>
        <?php
        }?>


    </tbody>
</table>

     <a href="<?php echo base_url();?>admin.php/products/add_product" class="bt_green"><span class="bt_green_lft"></span><strong>Add new item</strong><span class="bt_green_r"></span></a>
     <a href="<?php echo base_url();?>admin.php/products/view_product" class="bt_blue"><span class="bt_blue_lft"></span><strong>View all items from category</strong><span class="bt_blue_r"></span></a>
     <a href="#" class="bt_red"><span class="bt_red_lft"></span><strong>Delete items</strong><span class="bt_red_r"></span></a> 

继承人 jQuery 确认的 jquery:

/*
 * jQuery Plugin : jConfirmAction
 * 
 * by Hidayat Sagita
 * http://www.webstuffshare.com
 * Licensed Under GPL version 2 license.
 *
 */
(function($){

    jQuery.fn.jConfirmAction = function (options) {
        // Some jConfirmAction options (limited to customize language) :
        // question : a text for your question.
        // yesAnswer : a text for Yes answer.
        // cancelAnswer : a text for Cancel/No answer.
        var theOptions = jQuery.extend ({
            question: "Are You Sure ?",
            yesAnswer: "Yes",
            cancelAnswer: "Cancel"
        }, options);

        return this.each (function () {

            $(this).bind('click', function(e) {

                e.preventDefault();
                thisHref    = $(this).attr('href');

                if($(this).next('.question').length <= 0)
                    $(this).after('<div class="question">'+theOptions.question+'<br/> <span class="yes">'+theOptions.yesAnswer+'</span><span class="cancel">'+theOptions.cancelAnswer+'</span></div>');

                $(this).next('.question').animate({opacity: 1}, 300);

                $('.yes').bind('click', function(){
                    window.location = thisHref;
                });

                $('.cancel').bind('click', function(){
                    $(this).parents('.question').fadeOut(300, function() {
                        $(this).remove();
                    });
                });

            });

        });
    }

})(jQuery);

一切都运作良好,

然后我为列表进行了 ana jax 分页;

现在的问题是,在完成此任务后,jquery 确认不起作用,我希望将 jquery 脚本转换为像这样的简单 jquery 函数

function ask()
{

}

编辑:

我已经写了函数

function ask(obj)
{
alert('hii');
                    //var theOptions = jQuery.extend ({
            var question= "Are You Sure ?";
            var yesAnswer= "Yes";
            var cancelAnswer= "Cancel";
            //e.preventDefault();

                    var thisHref = $(obj).attr('href');
            alert(thisHref) ;
                if($(obj).next('.question').length <= 0)
                    $(obj).after('<div class="question">'+question+'<br/> <span class="yes">'+yesAnswer+'</span><span class="cancel">'+cancelAnswer+'</span></div>');

                $(obj).next('.question').animate({opacity: 1}, 300);

                $('.yes').bind('click', function(){
                    window.location = thisHref;
                });

                $('.cancel').bind('click', function(){
                    $(obj).parents('.question').fadeOut(300, function() {
                        $(obj).remove();
                    });
                });

}

我打电话给这个

<a href="<?php echo base_url();?>admin.php/products/delete_product/<?php echo $row['product_id'];?>" class="ask" onclick="ask(this);"><img src="<?php echo base_url();?>assets/admin_assets/images/trash.png" alt="" title="" border="0" /></a>

它也生效;但就在动画效果之后,它被重定向到链接,我需要让它保持不变,以便用户可以选择选项。但我不能...

MORE EDIT:

好的,我得到了答案;我用小代码返回false,它解决了我的问题

但是还有另一个问题

这行代码不起作用

$('.cancel').bind('click', function(){
                        $(obj).parents('.question').fadeOut(300, function() {
                            $(obj).remove();
                        });
                    });
4

1 回答 1

0

$('.ask').jConfirmAction();进入新页面后,您需要再次绑定到所有链接。

于 2013-01-17T08:00:10.997 回答