c# - 如何获取表格内的文本框值

标签 c# jquery html twitter-bootstrap html-table

我的网页中有一个表格(带有两个文本框“项目”和“计数”)。

enter image description here

我尝试访问每行中两个文本框的值。

请参阅下面的代码

 <table id="tbl-contents" class="table">
    <thead>
        <tr>
            <th>Item</th>
            <th>Count</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr class="clsRow">
            <td>
                @*
                <input type="text" class="form-control" placeholder="Item" data-required="true">*@
                <input id="txtItem" class="form-control" placeholder="Item" type="text" value="" tabindex="-1" name="" data-required="true">
            </td>
            <td>
                @*
                <input type="text" class="form-control" placeholder="Item Count" data-required="true">*@
                <input id="txtItemCount" class="form-control" placeholder="Item Count" type="text" value="" tabindex="-1" name="" data-required="true">
            </td>
        </tr>
        <tr class="clsRow">
            <td>
                <input type="text" class="form-control" placeholder="Item">
            </td>
            <td>
                <input type="text" class="form-control" placeholder="Item Count">
            </td>
            <td>
                <a class="clsDelContent"><i class="fa fa-minus-square" style="font-size: 22px;"></i></a>
            </td>
        </tr>
        <tr class="clsRow">
            <td>
                <input type="text" class="form-control" placeholder="Item">
            </td>
            <td>
                <input type="text" class="form-control" placeholder="Item Count">
            </td>
            <td>
                <a class="clsDelContent"><i class="fa fa-minus-square" style="font-size: 22px;"></i></a>
            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="3" style="text-align: right;">
                <a class="clsAddContent"><i class="fa fa-plus-square" style="font-size: 22px;"></i></a>
            </td>
        </tr>
    </tfoot>
</table>

脚本

        $('#tbl-contents tbody tr').each(function () {
            var customerId = $(this).find("td").html();



            alert(customerId);
        });

最佳答案

$('.clsRow').each(function() {
    var foo = $(this).find('input');
    var item = foo[0].value;
    var itemcount = foo[1].value;
})

JSFiddle

关于c# - 如何获取表格内的文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24305620/

相关文章:

java - INPUT 具有多个值,每个值有多个值

javascript - 如何从 JavaScript 中的字符串中删除 div 和 span 以外的 HTML 标记?

c# - 使用 SignalR 和 IProgress 接口(interface)的进度报告

c# - 过度使用委托(delegate)对性能来说是个坏主意吗?

c# - 将整数或十六进制值转换为 unicode 点

javascript - 将 daterangepicker 转换为 Angular 指令

c# - 扩展基于 C# 文件的资源管理器

javascript - 暂停 JW 播放器?

jquery - VueJS jQuery : computed value of parent data attribute undefined

html - CSS3 flex 属性不起作用?