javascript - Bootstrap 类 ="table"不起作用

标签 javascript html css twitter-bootstrap knockout.js

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

关闭 7 年前

我有一个简单的表格,正在使用 knockout 法来填充数据。 我正在尝试使用两个模板切换我的表体。我相信那是 boostrap 不喜欢的。请看看我的代码并给我建议。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script type='text/javascript' src='Scripts/knockout-3.1.0.js'></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">               
  <table class="table" data-bind="visible: folks().length > 0" >
    <thead>
      <tr>
        <th>Name</th>
        <th>Age</th>
        <th></th>
      </tr>
    </thead>
    <tbody data-bind="template: { name: templateToUse, foreach: folks}"></tbody>
  </table>
  <button data-bind="click: $root.addItem">New Item</button> 
</div>
</body>
</html>

<script type='text/javascript' src='Scripts/myscript.js'></script>
<script id="itemTmpl" type="text/html"> 
    <tbody>
       <tr>
           <td>
                <span data-bind="text: name"></span>
           </td>
            <td>
                 <span data-bind="text: age"></span>
            </td>            
            <td class="buttons">
                <button>Edit</button>
                <button>Delete</button>              
            </td>   
        </tr>                
    </tbody> 
</script>

<script id="editTmpl" type="text/html">
<tbody>
       <tr>
           <td>
                <input type="text" data-bind="value: name" ></input>                 
            </td>          
            <td>
                 <input data-bind="value: age"></input>               
            </td>
            <td class="buttons">
                <button>Done</button>
                <button>Cancel</button>
            </td>         
       </tr>
</tbody>
</script>

最佳答案

您在模板中不必要地包含了 tbody 标签。模板内容被插入到父标记中,在您的情况下,它已经是一个 tbody 元素。 Bootstrap 失败,因为呈现的表看起来像

<table>
 ...
 <tbody>
  <tbody> 
   ...

关于javascript - Bootstrap 类 ="table"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31054066/

上一篇:javascript - Angular Material 设计有效/无效输入

下一篇:html - css,导航除了最大宽度的部分

相关文章:

html - twitter bootstrap .hidden-lg 不工作

javascript - 根据浏览器大小定位元素

html - 当行添加到 flex 盒子时,盒子的高度增加

javascript - 缓存背景图像(javascript)

html - 如何使用 TypeScript 克隆包含 Angular 选择器的节点?

php - 用 PHP 处理 HTML 复选框表单

javascript - 图表 Canvas js设置动态数组

javascript - RxJS 响应式编程

javascript - 如何只改变一个按钮的颜色?

javascript 不允许我使用模数? %?