【发布时间】:2019-12-10 04:44:08
【问题描述】:
我正在尝试创建一个带有复制文本片段的按钮的 Rmarkdown 文档。我已经在在线 HTML 编辑器中独立测试了代码,当我按下按钮时,文本被成功复制到剪贴板。然后,我尝试使用 bookdown 作者 Yihui Xie.(https://bookdown.org/yihui/rmarkdown/) 推荐的代码块,使其在 Rmarkdown 文档中工作。 Rmarkdown文档编译成.html时,按钮不起作用(RStudio用来编译)。
---
author: "Nick Riches"
output:
html_document:
number_sections: no
toc: yes
toc_float:
collapsed: yes
pdf_document:
toc: yes
word_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{js, echo=FALSE}
function myFunction() {
var copyText = document.getElementById("myInput");
copyText.select();
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
```
<p>Click on the button to copy the text from the text field. Try to paste the text (e.g. ctrl+v) afterwards in a different window, to see the effect.</p>
<input type="text" value="Hello World" id="myInput">
<button onclick="myFunction()">Copy text</button>
【问题讨论】:
标签: html r-markdown