Сообщение от Faab
|
|
добавлена поддержка ff и ie8
<!doctype html>
<meta charset="utf-8"/>
<style>
table, td, th {
border: solid 1px;
border-collapse: collapse;
padding: 0.5em;
cursor: pointer;
}
</style>
<table class="table1">
<tr>
<td>как</td>
<td>так</td>
</tr>
<tr>
<th>вот</th>
<th>так</th>
</tr>
</table>
<br/>
<table class="table2">
<tr>
<td>good</td>
<td>day</td>
</tr>
</table>
<script>
(function () {
if(document.getElementsByClassName) {
getElementsByClass = function(classList, node) {
return (node || document).getElementsByClassName(classList)
}
} else {
getElementsByClass = function(classList, node) {
var node = node || document,
list = node.getElementsByTagName('*'),
length = list.length,
classArray = classList.split(/\s+/),
classes = classArray.length,
result = [], i,j;
for(i = 0; i < length; i++) {
for(j = 0; j < classes; j++) {
if(list[i].className.search('\\b' + classArray[j] + '\\b') != -1) {
result.push(list[i])
break
}
}
}
return result;
}
}
function addEvent(elem, evType, fn) {
if (elem.addEventListener) {
elem.addEventListener(evType, fn, false);
}
else if (elem.attachEvent) {
elem.attachEvent('on' + evType, fn)
}
else {
elem['on' + evType] = fn
}
}
var table1 = getElementsByClass("table1")[0];
var table2 = getElementsByClass("table2")[0];
addEvent(table1, "click", function (event) {
var target = event.target || window.event.srcElement;
if (target.tagName == "TD" || target.tagName == "TH") {
var tbody = table2.firstElementChild || table2.children[0];
tbody.appendChild(target.parentNode.cloneNode(true));
}
});
})();
</script>