html - 我的 SVG 源代码在 html 中不起作用 tags
问题描述
解决方案
javascript
为了使复制到剪贴板可行,需要几行代码button
另外我已经替换了你的pre
标签,xmp
你可以在这里使用仍然使用pre
标签,没有限制,并且需要一点点css
才能使标签具有溢出属性div
。
在xmp
标签中,您可以放置您的svg
代码,然后您可以使用此javascript
代码,以便您网站的用户可以复制您的代码svg
function CopyToClipboard(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.select().createTextRange();
document.execCommand("copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
document.execCommand("copy");
}
}
xmp {
border: 2px solid black;
overflow-x: scroll;
}
<button id="button1" onclick="CopyToClipboard('div1')">Click to copy</button>
<div id="div1">
<xmp><svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-bell" fill="currentColor"
xmlns="http://www.w3.org/2000/svg">
<path d="M8 16a2 2 0 0 0 2-2H6a2 2 0 0 0 2 2z" />
<path fill-rule="evenodd"
d="M8 1.918l-.797.161A4.002 4.002 0 0 0 4 6c0 .628-.134 2.197-.459 3.742-.16.767-.376 1.566-.663 2.258h10.244c-.287-.692-.502-1.49-.663-2.258C12.134 8.197 12 6.628 12 6a4.002 4.002 0 0 0-3.203-3.92L8 1.917zM14.22 12c.223.447.481.801.78 1H1c.299-.199.557-.553.78-1C2.68 10.2 3 6.88 3 6c0-2.42 1.72-4.44 4.005-4.901a1 1 0 1 1 1.99 0A5.002 5.002 0 0 1 13 6c0 .88.32 4.2 1.22 6z" />
</svg>
</xmp>
</div>
推荐阅读
- javascript - 启用了严格的 mime 类型检查,拒绝执行来自 ' 的脚本
' 它的 mime 类型 ('text/plain') 是不可执行的,并且 - keras - 翻转时间轴并应用 TimeDistributed RNN 来保留空间维度
- r - 如何为每个模拟运行循环并使用这些值创建一个新向量?
- ssl - WebRtc:无法为传输设置 SSL 角色
- linux - 是否必须使用 Cloud9 iDE 与 AWS 交互?
- c++ - 向量下标超出范围。比较向量的元素
- python - 如何在 python 中使用 GTK3 检查窗口是否存在并可能更新其中的数据?
- python - Python:根据列表不完整序列查找单词/字符串的基础序列
- angular - Angular - 如何在 NgFor 中创建动态模板变量
- java - 连接到Android设备时如何获取WIFI提供商名称