2016-03-11 46 views
1

我有一个嵌套的SPAN里面的另一个跨度没有被拾起我的jQuery - 我想都找到一种方法来使这项工作,并找出它为什么不是加工。嵌套跨度没有采取onClick

基本上,我有一个跨度,这实际上是一个弹窗(引导) 它的意思是确认删除记录。

下面是我有:

   <span 
       class="glyphicon glyphicon-remove" 
       data-placement="top" 
       data-toggle="popover" 
       style="cursor:pointer" 
       title="Confirm" 
       data-content="<center><span style='cursor:pointer' id='deleteRecordSpan' class='remove glyphicon glyphicon-remove'><p style='display:none'><?=$row['uniqueID'];?></p></span></center>" 
       ></span> 

跨度的数据内容的内部假设是第2个按钮(实际挂钩到jQuery的做我的AJAX命令按钮) - 和按钮出现并且具有与它相关的正确信息,但点击时,它永远不会触发jQuery的事件(按萤火虫)

我的JS:

<script> 
     $(document).ready(function() { 
      $('.remove').click(function() { 
       var input = input = $(this).text() 
       $.ajax({ // create an AJAX call... 
        data: { 
         uniqueid: input, 
        }, 
        type: 'POST', // GET or POST from the form 
        url: './ajax/deleteRecord.php', // the file to call from the form 
        success: function(response) { // on success.. 
         show10(); 
         allToday(); 
        } 
       }); 
      }); 
     }); 
     </script> 
+0

我可能是错的,但我认为引导具有stopPropagation对它们的元素,防止东西下面醒目的点击事件。我认为如果你能绕过你,你就是金。或者直接使用z-index和绝对值。 – Chris

+0

@Chris我不想因为这个而破坏我的网站的任何其他功能 - 我如何通过z-index和绝对路径将其移动? – GrumpyCrouton

+0

为什么你的HTML处于'data-content'属性,是一个错字,还是应该是这样?如果是后者,则标记由Bootstrap动态插入,并且您需要一个委托事件处理程序 - >'$(document).on('click','.remove',function(){...' – adeneo

回答

2

由于HTML是在data-content属性,引导插入标记动态,你会需要一个委托的事件处理程序

$(document).ready(function() { 
    $(document).on('click', '.remove', function() { 
     var input = $(this).text() 
     $.ajax({ 
      data: { 
       uniqueid: input, 
      }, 
      type: 'POST', 
      url: './ajax/deleteRecord.php', form 
      success: function(response) { 
       show10(); 
       allToday(); 
      } 
     }); 
    }); 
}); 
0

你的问题是在你span标记内的<p>标签。尝试将uniqueId作为跨度标签的数据属性,如下所示:

<center><span style='cursor:pointer' id='deleteRecordSpan' class='remove glyphicon glyphicon-remove' data-unique='<?=$row['uniqueID'];?>'></span></center> 

然后,您的唯一ID将不会显示。您还可以使用您的ID以这样的方式

var input = $(this).data('unique');