Показать сообщение отдельно
  #2 (permalink)  
Старый 04.05.2016, 17:33
Профессор
Отправить личное сообщение для Dilettante_Pro Посмотреть профиль Найти все сообщения от Dilettante_Pro
 
Регистрация: 27.11.2015
Сообщений: 2,899

Fierfoxik,
<!DOCTYPE html>
<html>
<head>
    <title>Untitled Page</title>
    <style>
        input[type='text']
        {
            width: 40px;
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script>
        $(function () {
            $('.add_str').click(function () {
                var mName = $('input[name = "mtrx_sel"]:checked').val()
                var mId = '#matrix_' + mName;
                $(mId + ' tr:first').clone().appendTo(mId);
                $(mId + ' tr:last td input').each(function (indx, elem) {
                    $(elem).prop({ 'placeholder': mName + $(mId).get(0).rows.length + ',' + (indx + 1) });
                });
            });
            $('.add_col').click(function () {
                var mName = $('input[name = "mtrx_sel"]:checked').val()
                var mId = '#matrix_' + mName;
                $(mId + ' tr td:last').clone().appendTo(mId + ' tr');
                $(mId + ' tr').each(function (indx, elem) {
                    var cells = $(elem).children();
                    $(elem.lastChild).children().prop({ 'placeholder': mName + (indx + 1) + ',' + cells.length });
                });
            });

        })
    </script>
</head>
<body>
    <label>
        <input checked="checked" name="mtrx_sel" type="radio" value="a" />Матрица А
    </label>
    <label>
        <input name="mtrx_sel" type="radio" value="b" />Матрица Б
    </label>
    <br />
    <button class="add_str btn-style" type="button">
        <i class="fa fa-plus" aria-hidden="true"></i>Добавить строку</button>
    <button class="add_col btn-style" type="button">
        <i class="fa fa-plus" aria-hidden="true"></i>Добавить столбец</button>
    <br />
    Матрица А
    <table id='matrix_a'>
        <tr>
            <td>
                <input type='text' placeholder='a1,1' />
            </td>
        </tr>
        <tr>
            <td>
                <input type='text' placeholder='a2,1' />
            </td>
        </tr>
    </table>
    Матрица Б
    <table id='matrix_b'>
        <tr>
            <td>
                <input type='text' placeholder='b1,1' />
            </td>
        </tr>
        <tr>
            <td>
                <input type='text' placeholder='b2,1' />
            </td>
        </tr>
    </table>
</body>
</html>
Ответить с цитированием