2014-01-22 78 views
2

我通過動態創建HTML來生成如圖所示的表格。我想添加一些驗證選擇,並希望保存數據。有沒有什麼辦法可以用JQuery來實現?Jquery DataTable

編輯 是否可以使用JQuery DataTable?

enter image description here

回答

2

使用下面的代碼ü可以得到一個選擇行的每個單元格的值,然後你可以驗證每個值。

$(document).ready(function() { 
$('#example td').live('click', function() { 
var anOpen = []; 
var nTr = this.parentNode; 
var i = $.inArray(nTr, anOpen); 
console.log(this); // clicked cell 
console.log(nTr); // clicked row 
$(this).parent().find("td").each(function() { 
    console.log($(this).html()); // logs each cell value 
}); 
}); 
});​ 

你可以參考鏈接here

you have mentioned about saving. Is it saving to db? 
+0

感謝。是的,我需要將它保存在數據庫中。 –

+0

你可以利用jquery的ajax調用將值存儲到你的db。請參閱http://www.myphpetc.com/2010/01/save-to-database-via-ajax-using-jquery.html,http://gordoncluster.wordpress.com/2013/09/18/how -to-插入數據 - 到 - 的MySQL數據庫-使用-jQuery的Ajax的PHP / –

0

您可以檢查您的答覆,這裏jquery-datatable-ajax-tutorial-with-example

var studentTable; 

jQuery(document).ready(function() { 

studentTable = jQuery('#studentListTable').dataTable({ 
"bJQueryUI" : true, 
"sPaginationType" : "full_numbers", 
"bRetrieve" : true, 
"bFilter" : true, 
"iDisplayLength": 10, 
"bProcessing" : true, 
"bServerSide" : false, 
"aoColumns" : [ { "bSearchable" : false,"bVisible" : false, 
"asSorting" : [ "asc" ] }, 
{"sWidth" : "20%","bSortable" : true }, 
{"sWidth" : "20%","bSortable" : true }, 
{"sWidth" : "20%","bSortable" : true }, 
{"sWidth" : "20%","bSortable" : true }, 
{"sWidth" : "20%","bSortable" : true } 
] 
}); 

jQuery(".ui-corner-br").addClass('ui-widget-header_custom '); 
});