Fill textbox with array value

时间:2018-02-03 08:30:04

标签: javascript jquery

I dynamically add textbox using jquery i want to fill each of them with same array value but every of them have different id

...

enter image description here

http://uupload.ir/files/owv5_1.jpg result i want for each textbox: http://uupload.ir/files/frwt_2.jpg

2 个答案:

答案 0 :(得分:1)

try this:

$('parentNodeIdOrClassName input').each(function(){
    $(this).val('your value');
})

答案 1 :(得分:0)

Try This.

<!DOCTYPE html><html>
<head>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        var index = 1;
        $(document).ready(function(){
            $('.addrow').click(function(e){
                var html = '';
                html += '\
                <tr>\
                    <td><input id="id'+ index++ +'" value="value1" type="text" name="filed1[]"></td>\
                    <td><input id="id'+ index++ +'" value="value2" type="text" name="filed2[]"></td>\
                    <td><input id="id'+ index++ +'" value="+" type="button" name="plus" ></td>\
                </tr>\
                ';
                $('table > tbody').append(html);
                return false;
            });
        });
    </script>
    <style type="text/css">
        table{
            width: 100%;
        }
        table td{
            border:1px solid #000;
        }
    </style>
</head>
<body>
    <button class="addrow">+</button>
    <table>
        <thead>
            <tr>
                <th>Column1</th>
                <th>Column2</th>
                <th>#</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</body>
</html>