删除从数据库里加载的商品类别数据时,点击事件在运行到$.confirm();这个函数时没有任何响应,直接跳到函数末尾结束,控制台也没有任何报错。
页面代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>商品分类列表</title>
<meta name="description"
content="MSUI: Build mobile apps with simple HTML, CSS, and JS components.">
<meta name="author" content="阿里巴巴国际UED前端">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<!-- Google Web Fonts -->
<link rel="stylesheet"
href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<link rel="stylesheet" href="../resources/css/shop/productcategorymanagement.css">
<script type='text/javascript'
src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript'
src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script>
//ga
</script>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?ba76f8230db5f616edc89ce066670710";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<div class="page-group">
<div id="page-grid" class="page">
<header class="bar bar-nav">
<a class="button button-link button-nav pull-left back"
href="/demos"> <span class="icon icon-left"></span> 返回
</a>
<h1 class="title">商品分类列表</h1>
</header>
<div class="content">
<div class="content-block">
<div class="row row-product-category">
<div class="col-40">类别</div>
<div class="col-40">优先级</div>
<div class="col-20">操作</div>
</div>
<div class="category-wrap">
</div>
</div>
<div class="content-block">
<div class="row">
<div class="col-50">
<a href="#" id="addProductCategory"
class="button button-big button-fill">新增</a>
</div>
<div class="col-50">
<a href="#"
class="button button-big button-fill button-success"
id="submit">提交</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script type='text/javascript'
src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript'
src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript'
src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
<script type='text/javascript' src='../resources/js/shop/productcategorymanagement.js'
charset='utf-8'></script>
</body>
</html>
js代码:
$(function() {
var addUrl = "/o2o/shopadmin/addproductcategories";
var listUrl = "/o2o/shopadmin/getproductcategorylist";
var deleteUrl = "/o2o/shopadmin/removeproductcategory";
getList();
function getList() {
$.ajax({
url : listUrl,
type : 'GET',
dateType : "json",
success : function(data) {
if (data.success) {
handleList(data.productCategoryList);
}
}
});
}
function handleList(data) {
var html = '';
data.map(function(item, index) {
html += '<div class="row row-product-category now"><div class="col-40 product-category-name">'
+ item.productCategoryName + '</div><div class="col-40">'
+ item.priority + '</div><div class="col-20">'
+ '<a href="#" data-id="'+item.productCategoryId+'" class="button delete">删除</a>'
+ '</div></div>';
});
$(".category-wrap").html(html);
}
$("#addProductCategory").click(function(){
var tempHtml = '<div class="row row-product-category temp">'
+'<div class="col-40"><input class="category-input category" type="text" placeholder="分类名"></div>'
+'<div class="col-40"><input class="category-input priority" type="number" placeholder="优先级"></div>'
+'<div class="col-20"><a href="#" class="button delete">删除</a></div>'
+'</div>';
$(".category-wrap").append(tempHtml);
});
$("#submit").click(function(){
var tempArr = $('.temp');
var productCategoryList = [];
tempArr.map(function(index,item){
var tempObj = {};
tempObj.productCategoryName = $(item).find('.category').val();
tempObj.priority = $(item).find('.priority').val();
if(tempObj.productCategoryName && tempObj.priority){
productCategoryList.push(tempObj);
}
});
$.ajax({
url:addUrl,
type:'POST',
data:JSON.stringify(productCategoryList),
contentType:'application/json',
success:function(data){
if(data.success){
$.toast('提交成功');
getList();
}else{
$.toast('提交失败');
}
}
});
});
$('.category-wrap').on('click','.row-product-category.temp .delete',
function(e){
console.log($(this).parent().parent());
$(this).parent().parent().remove();
});
$.confirm('确定吗?',function(){
alert("hello");
$.ajax({
url:deleteUrl,
type:'POST',
data:{
productCategoryId:target.dataset.id
},
dataType:'json',
success:function(data){
if(data.success){
$.toast("成功删除!");
getList();
}else{
$.toast("删除失败!");
}
}
});
});
});
});
SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需
了解课程