大佬教程收集整理的这篇文章主要介绍了javascript – 使用jquery在引导中获取所选表格行的值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
表码:
<table data-toggle="table" id="table-style" data-row-style="rowStyle" data-url="tables/data2.json" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-SELEct-item-name="toolbar1" data-pagination="true" data-sort-name="name" data-sort-order="desc" data-single-SELEct="false" data-click-to-SELEct="true" data-maintain-SELEcted="true"> <thead> <tr> <th data-field="state" data-checkBox="true"></th> <th data-field="id" >Item ID</th> <th data-field="name" data-sortable="true">Product Name</th> <th data-field="price" data-sortable="true">Actual Price</th> <th data-field="discount_price" data-sortable="true">Discount Price</th> <th data-field="stock_avail" data-sortable="true">Stock Available</th> </tr> </thead> </table>
JQuery代码:
$(document).ready(function() { $("#add_cart").click(function() { //foreach SELEcted row retrieve 'Item ID' values in array; //call ajax for otherpage.PHP?arr='Item ID array'; }); });
这是一个例子.
var checkedRows = []; $('#eventsTable').on('check.bs.table',function (e,row) { checkedRows.push({id: row.id,name: row.name,forks: row.forks}); console.log(checkedRows); }); $('#eventsTable').on('uncheck.bs.table',row) { $.each(checkedRows,function(index,value) { if (value.id === row.id) { checkedRows.splice(index,1); } }); console.log(checkedRows); }); $("#add_cart").click(function() { $("#output").empty(); $.each(checkedRows,value) { $('#output').append($('<li></li>').text(value.id + " | " + value.name + " | " + value.forks)); }); });
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/> <link rel="stylesheet" href="//cdnjs.cloudFlare.com/ajax/libs/bootstrap-table/1.8.1/bootstrap-table.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudFlare.com/ajax/libs/bootstrap-table/1.8.1/bootstrap-table.min.js"></script> <table id="eventsTable" data-toggle="table" data-height="300" data-url="https://api.github.com/users/wenzhixin/repos?type=owner&sort=full_name&direction=asc&per_page=100&page=1" data-pagination="true" data-search="true" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-toolbar="#toolbar"> <thead> <tr> <th data-field="state" data-checkBox="true"></th> <th data-field="name">Name</th> <th data-field="stargazers_count">Stars</th> <th data-field="forks_count">Forks</th> <th data-field="description">Description</th> </tr> </thead> </table> <button id="add_cart">Add to card</button> <ul id="output"></ul>
以上是大佬教程为你收集整理的javascript – 使用jquery在引导中获取所选表格行的值全部内容,希望文章能够帮你解决javascript – 使用jquery在引导中获取所选表格行的值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。