Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 引导表生成如何从表中设置选定值_Javascript_Jquery_Twitter Bootstrap 3_Bootstrap Table - Fatal编程技术网

Javascript 引导表生成如何从表中设置选定值

Javascript 引导表生成如何从表中设置选定值,javascript,jquery,twitter-bootstrap-3,bootstrap-table,Javascript,Jquery,Twitter Bootstrap 3,Bootstrap Table,我已经创建了一个从数据填充的引导表,我希望在用户单击“Get Selected”按钮时能够显示用户选中的值 如何获取选定的名称值 下面是我的密码 <table id="table" data-toggle="table" data-side-pagination="server" data-click-to-select="true"> <thead> <tr> <th data-field="state" data-che

我已经创建了一个从数据填充的引导表,我希望在用户单击“Get Selected”按钮时能够显示用户选中的值

如何获取选定的名称值

下面是我的密码

<table id="table" data-toggle="table" data-side-pagination="server"   data-click-to-select="true">
    <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>
      <fieldset>
        <input id="getSelected" type="button" value="Get Selected" />
        <input id="selectAll" type="button" value="Select All" />
        <input id="clear" type="button" value="Clear Selection" />
      </fieldset>

名称
星星
叉子
描述

选中/取消选中行时,只需执行基本检查即可:

以下是更新的JS:

var data = [
    {
        "name": "bootstrap-table",
        "stargazers_count": "526",
        "forks_count": "122",
        "description": "An extended Bootstrap table with radio, checkbox, sort, pagination, and other added features. (supports twitter bootstrap v2 and v3) "
    },
    {
        "name": "multiple-select",
        "stargazers_count": "288",
        "forks_count": "150",
        "description": "A jQuery plugin to select multiple elements with checkboxes :)"
    },
    {
        "name": "bootstrap-show-password",
        "stargazers_count": "32",
        "forks_count": "11",
        "description": "Show/hide password plugin for twitter bootstrap."
    },
    {
        "name": "blog",
        "stargazers_count": "13",
        "forks_count": "4",
        "description": "my blog"
    },
    {
        "name": "scutech-redmine",
        "stargazers_count": "6",
        "forks_count": "3",
        "description": "Redmine notification tools for chrome extension."
    }
];

$(function () {
    $('#table').bootstrapTable('load', {total: 5, rows: data});
    checkedRows = [];
    $('#table').on('check.bs.table', function (e, row) {
  checkedRows.push({name: row.name, stargazers_count: row.stargazers_count, forks_count: row.forks_count, description: row.description});
  console.log(checkedRows);
});

$('#table').on('uncheck.bs.table', function (e, row) {
  $.each(checkedRows, function(index, value) {
    if (value.name === row.name) {
      checkedRows.splice(index,1);
    }
  });
  console.log(checkedRows);
});

    $('#getSelected').click(function() {
    console.log(checkedRows);
    })
});

非常感谢。如何清除选中的值,或者何时使用“全选”按钮获取所有选中的值