【问题标题】:Jquery Confirm and CodeIgniter DeleteJquery Confirm 和 CodeIgniter 删除
【发布时间】:2013-04-26 15:39:52
【问题描述】:

我正在使用此管理面板模板确认框。

http://themepixels.com/main/themes/demo/webpage/shamcey/elements.html

当我点击确认框的 ok 按钮时,ajax 部分不起作用。

我不明白为什么它不起作用?

这是我的代码:

//jquery部分

<script>
jQuery(document).ready(function(){
if(jQuery('.confirmbutton').length > 0) {
    jQuery('.confirmbutton').click(function(){
        jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
             if(r==true){
                var article_id=$(this).attr("id");
                 $.ajax({
                    type:"POST",
                    url: "<?php echo site_url()?>admin/delete",data: "id="+article_id+"&categ=article",asynchronous: true,cashe: false,beforeSend: function(){},
                    success: function(){
                    $('#delete_link_'+article_id).hide();
                    }
                    }); 
             }
        });
    });
}
});
</script>

//HTML

<tr id="delete_link_15">
<td>15</td>
<td>1</td>
<td>asg</td>
<td>etc</td>
<td>etc</td>
<td>
<span class="btn-group">
<a class="btn btn-small confirmbutton"><i class="icon-trash"></i></a>
</span>
</td>
</tr>        

【问题讨论】:

  • 你能不能把:console.log('Before If') 放在if(r==true) 条件之前,console.log('Inside If') 放在if(r==true){ 之后
  • var parca=jQuery(this).parent('span').parent('td').parent('tr').attr("id");这部分不起作用。
  • var article_id=$(this).attr("id"); - 检索 id 属性的上下文无效。

标签: jquery codeigniter dialog confirm


【解决方案1】:

HTML 代码

<tr id="delete_link_15">
<td>15</td>
<td>1</td>
<td>asg</td>
<td>etc</td>
<td>etc</td>
<td>
<span class="btn-group">
<a class="btn btn-small confirmbutton" onclick="deleteArticle('15')"><i class="icon-trash"></i></a>
</span>
</td>
</tr> 

jQuery 代码

<script>
jQuery(document).ready(function(){
function deleteArticle(article_id)
{
             var r=confirm("Can you confirm this?")
             if(r==true){

                 $.ajax({
                    type:"POST",
                    url: "<?php echo site_url()?>admin/delete",data: "id="+article_id+"&categ=article",asynchronous: true,cashe: false,beforeSend: function(){},
                    success: function(){
                    $('#delete_link_'+article_id).hide();
                    }
                    }); 
             }

}
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 2015-11-26
    • 2012-12-25
    • 2019-02-03
    • 1970-01-01
    相关资源
    最近更新 更多