以下代码适用于Firefox,但不适用于根本没有运行的Chrome脚本,甚至不适用于ALERT。
为什么?
脚本应该从DB中删除行并从屏幕上隐藏ARTICLE。
HTML
<article class="row" id="410">
<a href='#' class="btn btn-default btn-xs left delButton" type="comment" delID="410" >DELETE</a>
</article>
<article class="row" id="411">
<a href='#' class="btn btn-default btn-xs left delButton" type="comment" delID="411" >DELETE</a>
</article>
JS
$(function() {
$(document).on('click','.delButton',function() {
// $(".delButton").click(function(){
var element = $(this);
var delID = element.attr("delID");
var type = element.attr("type");
var info = 'delID=' + delID + '&type=' + type;
alert (info);
var check = confirm('DELETE?');
if(check){
$.ajax({
type: "GET",
url: "ajax/delete_element.php",
data: info,
success: function(data){
if (data)
$("#"+delID).animate({ opacity: "hide" }, "slow");
}
});
}
return false;
});
});
答案 0 :(得分:2)
它确实在Chrome上运行......
$(function() {
$(document).on('click', '.delButton', function() {
// $(".delButton").click(function(){
var element = $(this);
var delID = element.attr("delID");
var type = element.attr("type");
var info = 'delID=' + delID + '&type=' + type;
alert(info);
var check = confirm('DELETE?');
if (check) {
$.ajax({
type: "GET",
url: "ajax/delete_element.php",
data: info,
success: function(data) {
if (data)
$("#" + delID).animate({
opacity: "hide"
}, "slow");
}
});
}
return false;
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<article class="row" id="410">
<a href='#' class="btn btn-default btn-xs left delButton" type="comment" delID="410">DELETE</a>
</article>
<article class="row" id="411">
<a href='#' class="btn btn-default btn-xs left delButton" type="comment" delID="411">DELETE</a>
</article>
&#13;