首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在每个中继器项目上显示值

在每个中继器项目上显示值
EN

Stack Overflow用户
提问于 2019-03-18 03:32:08
回答 2查看 11.3K关注 0票数 2

我使用jquery中继器创建一个动态表单。

代码语言:javascript
复制
<div class="repeater">
  <table border="1">
    <thead>
      <tr style=>
        <th>ID</th>
        <th>Name</th>
      </tr>
    </thead>
    <tbody data-repeater-list="data">
      <tr data-repeater-item>
        <td><input name="this_id" value="1"></td>
        <td><input name="this_name"></td>
      </tr>
    </tbody>
  </table>
  <button data-repeater-create>Add New</button>
</div>

<script>
  $('.repeater').repeater();

  /* Not working if use below code :
  Reference : https://github.com/DubFriend/jquery.repeater

    $('.repeater').repeater({
      defaultValues: {
        'this_id': '1'
      }
    });
  */
</script>

当我按下“添加新”按钮时,为什么this_id的默认值不出现(空白值)。我的密码有什么问题吗?

更新: https://jsfiddle.net/b6tryg9m/

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-18 10:02:33

您可以在输入元素上设置type=“文本”。下面是一个有用的例子:

代码语言:javascript
复制
$('.repeater').repeater({
  defaultValues: {
    'this_id': '1',
    'this_name': 'foo'
  }
});
代码语言:javascript
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.min.js"></script>
<div class="repeater">
  <table border="1">
    <thead>
      <tr style="background-color:#cecece">
        <th>ID</th>
        <th>Name</th>
      </tr>
    </thead>
    <tbody data-repeater-list="data">
      <tr data-repeater-item>
        <td><input type="text" name="this_id" value="1"/></td>
        <td><input type="text" name="this_name"/></td>
      </tr>
    </tbody>
  </table>
  <br>
  <button data-repeater-create>Add New</button>
</div>

票数 2
EN

Stack Overflow用户

发布于 2019-03-18 10:20:40

您必须定义输入类型。

代码语言:javascript
复制
type="text"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55214401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档