당신은 쉽게 각 td
에 click
및 mouseover
이벤트를 바인딩 할 수 있습니다 jQuery.
$("table-selector tr td").each(function(){
$(this).click(function(){
// TODO with click
}).hover(function(){
// TODO with mouseover
},function(){
// TODO with mouseout
});
}
UPDATE : 셀 인덱스 및 행 인덱스를 분리하고 각 td
의 데이터로서 테마 저장 :
$("#myTable tr").each(function(r){
var row = r;
$("td", this).each(function(d){
var cell = d;
$(this)
.data("rowIndex", row)
.data("cellIndex", cell)
.click(function(){
$("#message").text("Row-Index is: " + $(this).data("rowIndex") +
" and Cell-Index is: " + $(this).data("cellIndex"));
})
.hover(
function(){
$(this).addClass("td-over").css({"text-align":"center"});
},function(){
$(this).removeClass("td-over").css({"text-align":"left"});
});
});
});
See the full-demo here at jsfiddle
jQuery를 사용합니다. – Petah