|
|
|
| Приветствую!
Столкнулся со следующим :
при добавлении строки в таблицу через JS присвоить name тегу tr через tr.name не получается, только через setAttribute.
<!DOCTYPE html>
<html>
<head>
<script>
var count = 0;
function add_str(a) //Добавить строку
{
var text = '<td contenteditable="true" class = "td3"> 1</td>\
<td contenteditable="true" class = "td3"> 1</td>\
<td contenteditable="true" class = "td2"> 1</td>\
<td contenteditable="true" class = "td1"> 1</td>\
<td contenteditable="true" class = "td2"> 1</td>\
<td contenteditable="true" class = "td2"> 1</td>\
<td contenteditable="true" class = "td2"> 1</td>\
<td contenteditable="true" class = "td2"> 1</td>\
<td contenteditable="true" class = "td1"> 1</td>\
<td contenteditable="true" class = "td3"><input type = "button" value = "Удалить строку" class = "del_str"\
onclick = "var x = document.getElementById(\'tr' + count + '\');x.parentNode.removeChild(x);"></td>';
var newTr = document.createElement('tr');
newTr.id = "tr" + count;
newTr.name = "tb12";
newTr.innerHTML = text;
document.getElementById(a).appendChild(newTr);
count++;
}
</script>
</head>
<body>
<table class="gradient">
<tbody id = 'tbody2'>
</tbody>
</table>
<input type = 'button' value = 'Добавить строку' class = 'add_str' onclick = 'add_str("tbody2");'>
</body>
</html>
|
Ни где не нашел информации про этот момент. Объясните пожалуйста? | |
|
|
|
|
|
|
|
для: mikado3333
(29.01.2015 в 15:15)
| | Потому, что в HTML атрибут name для тега TR не определен. | |
|
|
|