$(document).ready(function(){ //寶寶卡片新增 $(document).on("click", ".bady-add-btn", function(){ let _this = $(this) let index = _this.data('index') $.ajax({ url:"/member/ajax/ajax_baby_card.php", type:"POST", data: { index: index }, cache:false, error:function(error){ alert('網路連線過慢,網頁請重新整理'); }, success:function(res){ _this.data("index",parseInt(_this.data('index')) + 1) //console.log(_this.data('index')) $("#babyCardList").append(res); $("#noBaby").prop("checked", false) } }); }) //寶寶卡片刪除 $(document).on("click", ".card-closer", function(){ let _this = $(this) let card = _this.parents(".baby-card") if(confirm("確認刪除寶貝資料?")){ card.remove(); } }) //孕期狀態切換 $(document).on("change", ".baby-status-radio", function(){ let _this = $(this) let card = _this.parents(".baby-card") if(_this.data("show") == "card-type1"){ card.find(".card-type1").addClass("in-active") card.find(".card-type1 input[data-fun]").each(function(){ $(this).attr("fun", $(this).data("fun")) }) card.find(".card-type2").removeClass("in-active") card.find(".card-type2 input[data-fun]").attr("fun", "") }else{ card.find(".card-type2").addClass("in-active") card.find(".card-type2 input[data-fun]").each(function(){ $(this).attr("fun", $(this).data("fun")) }) card.find(".card-type1").removeClass("in-active") card.find(".card-type1 input[data-fun]").attr("fun", "") } }) //勾選沒有小朋友清空現有卡片 $(document).on("click", ".no-baby-btn", function(e){ e.preventDefault() let checkbox = $("#noBaby") let cardlist = $("#babyCardList") if(!checkbox.prop("checked")){ if(cardlist.find(".baby-card").length > 0){ //有已添加的寶寶資料 if(confirm("將會刪除已添加的寶貝資料,確定要刪除嗎?")){ $("#babyCardList").empty() checkbox.prop("checked", true) } }else{ checkbox.prop("checked", true) } }else{ checkbox.prop("checked", false) } }) })