问题描述
我有一个带有截面模型的小应用程序。该部分有一个标题和一个正文。正文使用动作文本。
<div class='mt-5 mb-5'>
<h3 value="<%= section.title %>" id="st<%= section.id %>"><%= section.title %></h3>
<div value="" id="<%= section.id %>"><%= section.body %></div>
<button class="btn btn-primary mt-5" onclick="copy_function('<%= section.title %>')">copy Title</button>
</div>
<script>
function copy_function(id) {
var input_temp = document.createElement("input");
input_temp.value = id;
document.body.appendChild(input_temp);
input_temp.select();
document.execCommand("copy");
document.body.removeChild(input_temp);
}
</script>
我想为主体制作一个类似的按钮,但 HTML 元素使它有点棘手。
<div class='mt-5 mb-5'>
<h3 value="<%= section.title %>" id="st<%= section.id %>"><%= section.title %></h3>
<div value="<%= section.body.html_safe? %>" id="sb<%= section.id %>"><%= section.body %></div>
<button class="btn btn-primary mt-5" onclick="copy_function('<%= section.title %>')">copy Title</button>
<button class="btn btn-primary mt-5" onclick="copy_body_function('<%= section.body.html_safe? %>')">copy Body</button>
</div>
<script>
function copy_function(id) {
var input_temp = document.createElement("input");
input_temp.value = id;
document.body.appendChild(input_temp);
input_temp.select();
document.execCommand("copy");
document.body.removeChild(input_temp);
}
function copy_body_function(id) {
var input_temp = document.createElement("input");
input_temp.value = id;
document.body.appendChild(input_temp);
input_temp.select();
document.execCommand("copy");
document.body.removeChild(input_temp);
}
</script>
有关如何处理 js 按钮中的正文 HTML 元素的任何提示
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)