复制包含输入到剪贴板的表

时间:2018-10-18 12:43:26

标签: jquery clipboard.js

我有此密码

new ClipboardJS('#copy-btn');
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
 
<button id="copy-btn" class="btn" data-clipboard-target="#table-materials">
    Copy to clipboard
</button>
 
 <table id="table-materials" class="table table-sm table-bordered">

                  <thead>
                      <tr>
                          <th><span class="required">Number</span></th>
                          <th>Name</th>
                          <th>Action</th>
                      </tr>
                  </thead>

                  <tbody>
                      
                      <tr>
                          <td>
                              <input type="hidden" data-bind="textInput: id" />
                              <input type="text" value="John Doe"/>
                          </td>
                          <td><input class="form-control form-control-sm" type="text" data-bind="textInput: name" style="min-width:350px;" readonly /></td>
                          <td><button>Delete</button></td>
                      </tr>

                      <tr>
                          <td>
                              <input type="hidden" data-bind="textInput: id" />
                              <input type="text" value="Jane Doe"/>
                          </td>
                          <td><input class="form-control form-control-sm" type="text" data-bind="textInput: name" style="min-width:350px;" readonly /></td>
                          <td><button>Delete</button></td>
                      </tr>

                      <tr>
                          <td colspan="2">Sum</td>
                          <td><span>13245646</span> kg</td>
                      </tr>
                  </tbody>
              </table>

此解决方案有两个问题

  • 输入框也被复制(不仅是值)
  • 当我更改一些输入值并将表粘贴到记事本中时,它可以工作,但是当我将其粘贴到excel中时。无论如何,显示时间页上仍然有旧值。

你怎么看?

0 个答案:

没有答案