Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 07.04.2016, 21:03
Интересующийся
Отправить личное сообщение для failoflife Посмотреть профиль Найти все сообщения от failoflife
 
Регистрация: 04.04.2016
Сообщений: 14

Выбор таблицы
У нас есть две таблицы.
Два радио-инпута.
И одна кнопка.

С помощью инпутов выбираем Таблицу в которую будем добавлять колонку с помощью нажатия кнопки.


<table class="myTable1">
  <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
   <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
</table>
<table class="myTable2">
<hr>
  <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
   <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
</table>
<input class="one" type="radio" id="oneTable" value="oneTable" name="table" checked>Таблица 1
<input class="two" type="radio" id="twoTable" value="twoTable" name="table">Таблица 2

<input id="addcol" type="button" value="Add Column" />


var table;

		$('input:radio[name=table]').change(function() {
        if (this.value == 'oneTable') {
            table = $(".one");
        }
        else if (this.value == 'twoTable') {
           table = $(".two");
        }
    });
    
    $("#addcol").click(function() {
        $("tr", table).append(function(i) {
            var num = "a" + (i + 1) + "," + ($("td", this).length + 1);
            return $("<td>").append($("<input/>", {
                attr: {
                    size: "2",
                    maxlength: "2",
                    placeholder: num
                }
            }))
        })
    });
Ответить с цитированием
  #2 (permalink)  
Старый 07.04.2016, 21:31
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

failoflife,

<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
</style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script>
 $(function(){
    var i = $("[name=table]"), t = $(".myTable");
    $("#addcol").click(function() {
        var table = t.eq(i.index(i.filter(":checked")));
        $("tr", table).append(function(i) {
            var num = "a" + (i + 1) + "," + ($("td", this).length + 1);
            return $("<td>").append($("<input/>", {
                attr: {
                    size: "2",
                    maxlength: "2",
                    placeholder: num
                }
            }))
        })
    });

   })
  </script>
</head>

<body>
<table class="myTable">
  <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
   <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
</table>
<table class="myTable">
<hr>
  <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
   <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
</table>
<hr>
<table class="myTable">
  <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
   <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
</table>
<table class="myTable">
<hr>
  <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
   <tr>
    <td><input type="text"></td>
    <td><input type="text"></td>
  </tr>
</table>
<input  type="radio"  name="table" checked>Таблица 1
<input  type="radio"  name="table">Таблица 2
<input  type="radio"  name="table">Таблица 3
<input  type="radio"  name="table">Таблица 4
<input id="addcol" type="button" value="Add Column" />

</body>
</html>
Ответить с цитированием
  #3 (permalink)  
Старый 07.04.2016, 21:50
Интересующийся
Отправить личное сообщение для failoflife Посмотреть профиль Найти все сообщения от failoflife
 
Регистрация: 04.04.2016
Сообщений: 14

рони, вааау. Спасибо, Рони. Сегодня вообще выручил. )
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Генерация таблицы из JSON Lemme Общие вопросы Javascript 34 23.07.2015 21:55
выбор значений из таблицы osetr Общие вопросы Javascript 9 12.11.2014 16:46
фильтрация .csv таблицы br1ck Элементы интерфейса 0 13.11.2013 08:35
Через ajax отправить много данных из таблицы на сервер Heger jQuery 3 29.08.2012 18:51
Выбор из таблицы HOmevl Общие вопросы Javascript 4 15.09.2011 01:40