简体   繁体   English

使用 jquery 在可编辑表中获取数据

[英]get the data after in editable Table using jquery

I have a web app, frontend using HTML5, backend using Django.我有一个 web 应用程序,前端使用 HTML5,后端使用 Django。

There's a editable table in my frontend page.我的前端页面中有一个可编辑的表格。 I want to select the data using jquery, but name and id selector all could not work for me.我想 select 使用 jquery 的数据,但名称和 ID 选择器都不适合我。

               <table contenteditable='true' class="table table-bordered table-sm" width="100%" cellspacing="0" style="font-size: 1.0rem;"
                   id="bk-table"
                   data-toggle="table"
                   data-toolbar="#toolbar"
                   data-cookie="true"
                   data-cookie-id-table="materialId"
                   data-show-columns="true"
                   data-show-refresh="true"
                   data-show-fullscreen="true"
                   data-show-export="true"
                   data-height="650"
                    data-click-to-select="true"
                   data-id-field="id"
                   data-show-footer="true"
                   data-url="/api/materials/"
                   data-query-params="queryParams"
                   data-remember-order="true"
                   data-pagination="true"
                   data-side-pagination="server"
                   data-total-field="count"
                   data-data-field="results">
                <thead class="thead-dark" >
                <tr>
                      <th data-field="state" data-checkbox="true"></th>
                    <th data-field="courseCode"  data-formatter="renderCourse">Course Code</th>
                    <th data-field="type">Course Type</th>
                    <th data-field="book.title">Course Material Title</th>
                    <th name="Author" data-field="book.author">Author/Editor</th>
                    <th  name="pub_date"  data-field="book.pub_date">Publication Year</th>                   

                </tr>
                </thead>
            </table>

<script>
        $('#bk-table').on('check.bs.table', function (e, row) {
            alert($('td[name="pub_date"]').val());   
});</script>

After editing the table, I have tried alert($('td[name="pub_date"]').val()), alert($("[name='pub_date']").val()), none of the above could show the data in table, they all show "undefined".编辑表格后,我尝试了 alert($('td[name="pub_date"]').val()), alert($("[name='pub_date']").val()), none以上可以显示表格中的数据,它们都显示“未定义”。

Maybe this could be the answer.也许这就是答案。
Otherwise post the full body of your table.否则张贴您的表格的完整内容。
You only post the header line of your Table.您只发布表格的 header 行。

 $('#bk-table').click(function() { if ($(this).attr("contentEditable") == "true") { console.log($('th[name="pub_date"]').text()); } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table contenteditable='true' class="table table-bordered table-sm" width="100%" cellspacing="0" style="font-size: 1.0rem;" id="bk-table" data-toggle="table" data-toolbar="#toolbar" data-cookie="true" data-cookie-id-table="materialId" data-show-columns="true" data-show-refresh="true" data-show-fullscreen="true" data-show-export="true" data-height="650" data-click-to-select="true" data-id-field="id" data-show-footer="true" data-url="/api/materials/" data-query-params="queryParams" data-remember-order="true" data-pagination="true" data-side-pagination="server" data-total-field="count" data-data-field="results"> <thead class="thead-dark"> <tr> <th data-field="state" data-checkbox="true"></th> <th data-field="courseCode" data-formatter="renderCourse">Course Code</th> <th data-field="type">Course Type</th> <th data-field="book.title">Course Material Title</th> <th name="Author" data-field="book.author">Author/Editor</th> <th name="pub_date" data-field="book.pub_date">Publication Year</th> </tr> </thead> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM