[转]jQuery: get table column/row index remove table column (by column number)
本文转自:http://www.xinotes.org/notes/note/1087/
<!DOCTYPE html>
<html>
<head>
	<title>jQuery Table</title>
	<style type="text/css">
	body {
		font-family: sans-serif;
	}
	table {
		border-collapse: collapse;
		margin-bottom: 5px;
	}
	td {
		padding: 4px;
		border: #4488aa 1px solid;
	}
	input {
		text-align: right;
		padding: 2px;
		width: 20px;
	}
	</style>
	<script type="text/javascript" 
		src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
	</script>
	<script type="text/javascript">
	$(function() {
		$('td').click(function() {
			var tr = $(this).parent();
			for (var i = 0; i < tr.children().length; i++) {
				if (tr.children().get(i) == this) {
					var column = i;
					break;
				}
			}
			var tbody = tr.parent();
			for (var j = 0; j < tbody.children().length; j++) {
				if (tbody.children().get(j) == tr.get(0)) {
					var row = j;
					break;
				}
			}
			$('span').text(row + ', ' + column);
		});
	});
	</script>
</head>
<body>
	<h1>Table Cell Value</h1>
	<table>
		<tr><td>Cell 1-1</td><td>Cell 1-2</td><td>Cell 1-3</td></tr>
		<tr><td>Cell 2-1</td><td>Cell 2-2</td><td>Cell 2-3</td></tr>
		<tr><td>Cell 3-1</td><td>Cell 3-2</td><td>Cell 3-3</td></tr>
	</table>
	You clicked cell: <span>None</span>
</body>
</html>
本文转自:http://www.jquery4u.com/snippets/jquery-remove-table-column-by-column-number/
Simple jQuery code snippet to remove an entire table column based on the column number. It also removes the table row heading associated with the removed column.
//remove the 1st column
//remove the 2nd column
//remove the nth column
posted on 2013-07-11 09:41 freeliver54 阅读(1173) 评论(2) 收藏 举报
 
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号