實習開發網站,常遇到一些功能需求要上網查詢,整理成筆記以後再用到就不用又從頭開始找,也希望幫助到正在找學這些功能的人
新增功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| $(document).on("click", ".add", function(){ var empty = false; var input = $(this).parents("tr").find('input[type="text"]'); input.each(function(){ if(!$(this).val()){ $(this).addClass("error"); empty = true; } else { $(this).removeClass("error"); } }); $(this).parents("tr").find(".error").first().focus(); if(!empty){ $('input[type=text]').each(function(){ $(this).parent("td").html($(this).val()); }); $('input[type=date]').each(function(){ $(this).parent("td").html($(this).val()); }) $(this).parents("tr").find(".add, .edit").toggle(); $(".add-new").removeAttr("disabled"); } });
|
編輯功能
1 2 3 4 5 6 7 8 9 10 11 12
| $(document).on("click", ".edit", function() { $(this).parents("tr").find("td:not(:last-child)").each(function(index, value){ if (index == 1) { $(this).html('<input type="date" class="form-control" value="' + $(this).text() + '">'); } else { $(this).html('<input type="text" class="form-control" value="' + $(this).text() + '">'); } }); $(this).parents("tr").find(".add, .edit").toggle(); $(".add-new").attr("disabled", "disabled"); });
|
刪除功能
1 2 3 4
| $(document).on("click", ".delete", function(){ $(this).parents("tr").remove(); $(".add-new").removeAttr("disabled"); });
|
ref: https://www.tutorialrepublic.com/faq.php