【发布时间】:2016-09-27 11:34:28
【问题描述】:
可能的问题在哪里,我有一个返回 json 的服务,用这个返回来骑我的桌子。
如果我留下 statisc 记录,它会将插件作为下面的确认码运行:
<td><strong>Fatura Abril</strong><br /> Este é um aviso de que sua fatura do mÊs 04 está vencendo</td>
<td class="text-right"></a>
<a data-toggle="confirmation" class="label label-danger" type="button" id="not-basic"><i class="fa fa-times"></i></a>
</td>
但是如果你使用函数通过json返回和组装数据,表是monstada但插件确认不起作用。
<script type="text/javascript">
$(document).ready(function(){
var url="phptabela.php"; // PHP File
//var url="getposts.json"; // JSON File
$.getJSON(url,function(data){
console.log(data);
$.each(data.data, function(i,post){
var newRow =
"<tr>"
+"<td><strong>"+post.titulo+"</strong><br />" +post.texto+"</td>"
+"<td class='text-right'></a> "
+"<a data-toggle='confirmation' class='btn btn-default label label-danger' type='button' id='not-basic'> "
+"<i class='fa fa-times'></i></a> "
+"</td>"
+"</tr>" ;
$(newRow).appendTo("#json-data");
});
});
});
</script>
我正在使用这个插件: http://bootstrap-confirmation.js.org/
【问题讨论】:
-
在循环中使用 html ID 绝不是一个好主意,因为 ID 必须是唯一的。
标签: php jquery ajax twitter-bootstrap