我无法让 Javascript 将文本复制到剪贴板
I can't get my Javascript to copy text to the clipboard
如果可能的话,需要别人的一点帮助。
我正在为我的网站制作一个下拉菜单 DIV,它允许用户按下一个按钮并将各种符号的 HTML 字符代码复制到剪贴板。这还不是最终格式 - 我刚刚创建了一个简单的 HTML 页面来测试功能。
问题是它不起作用!我不确定我做错了什么。
这是我的 HTML,它结合了基本的内联样式表和 Javascript:
function copyFunction() {
/* Get the text field */
var copyText = document.getElementById("charInput");
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
/* Copy the text inside the text field */
navigator.clipboard.writeText(copyText.value);
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Text Formatting</title>
<style>
body {
background-color: #309bbf;
}
.chardisp {
width: 40px;
text-align: center;
}
.charhead {
font-family: sans-serif;
font-size: 14px;
color: white;
}
.charbutt {
width: 100%;
background-color: white;
border-radius: 2px;
padding: 3px;
font-family: sans-serif;
font-size: 11px;
color: black;
outline: 0;
}
.charbutt:hover {
cursor: pointer;
}
</style>
</head>
<body>
<table border="0">
<tr>
<td colspan="5"><p class='charhead'>FORMATTING</p></td>
</tr>
<tr>
<td class='chardisp'><button value='<b>' id='charInput' class='charbutt' onclick=\"copyFunction\"><b></button></td>
<td class='chardisp'><button value='<i>' id='charInput' class='charbutt' onclick=\"copyFunction\"><i></button></td>
<td class='chardisp'><button value='<u>' id='charInput' class='charbutt' onclick=\"copyFunction\"><u></button></td>
<td class='chardisp'><button value='<b>[ ... ]</b>' id='charInput' class='charbutt' onclick=\"copyFunction\"><b>[ ... ]</b></button></td>
<td class='chardisp'><button value='<br/>' id='charInput' class='charbutt' onclick=\"copyFunction\"><br/></button></td>
</tr>
<tr>
<td colspan="5"><p class='charhead'>SYMBOLS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='™' id='charInput' class='charbutt' onclick=\"copyFunction\">™</button></td>
<td class='chardisp'><button value='®' id='charInput' class='charbutt' onclick=\"copyFunction\">®</button></td>
<td class='chardisp'><button value='¡' id='charInput' class='charbutt' onclick=\"copyFunction\">¡</button></td>
<td class='chardisp'><button value='¿' id='charInput' class='charbutt' onclick=\"copyFunction\">¿</button></td>
<td class='chardisp'><button value='ß' id='charInput' class='charbutt' onclick=\"copyFunction\">ß</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&' id='charInput' class='charbutt' onclick=\"copyFunction\">&</button></td>
<td class='chardisp'><button value='$quot;' id='charInput' class='charbutt' onclick=\"copyFunction\">"</button></td>
<td class='chardisp'><button value='£' id='charInput' class='charbutt' onclick=\"copyFunction\">£</button></td>
<td class='chardisp'><button value='€' id='charInput' class='charbutt' onclick=\"copyFunction\">€</button></td>
<td class='chardisp'><button value='$' id='charInput' class='charbutt' onclick=\"copyFunction\">$</button></td>
</tr>
<tr>
<td class='chardisp'><button value='¼' id='charInput' class='charbutt' onclick=\"copyFunction\">¼</button></td>
<td class='chardisp'><button value='⅓' id='charInput' class='charbutt' onclick=\"copyFunction\">⅓</button></td>
<td class='chardisp'><button value='⅔' id='charInput' class='charbutt' onclick=\"copyFunction\">⅔</button></td>
<td class='chardisp'><button value='½' id='charInput' class='charbutt' onclick=\"copyFunction\">½</button></td>
<td class='chardisp'><button value='¾' id='charInput' class='charbutt' onclick=\"copyFunction\">¾</button></td>
</tr>
<tr>
<td class='chardisp'><button value=':' id='charInput' class='charbutt' onclick=\"copyFunction\">:</button></td>
<td class='chardisp'><button value=';' id='charInput' class='charbutt' onclick=\"copyFunction\">;</button></td>
<td class='chardisp'><button value='♪' id='charInput' class='charbutt' onclick=\"copyFunction\">♪</button></td>
<td class='chardisp'><button value='#' id='charInput' class='charbutt' onclick=\"copyFunction\">#</button></td>
<td class='chardisp'><button value='/' id='charInput' class='charbutt' onclick=\"copyFunction\">/</button></td>
</tr>
<tr>
<td colspan="5"><p class='charhead'>ACCENTED CHARACTERS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='À' id='charInput' class='charbutt' onclick=\"copyFunction\">À</button></td>
<td class='chardisp'><button value='Á' id='charInput' class='charbutt' onclick=\"copyFunction\">Á</button></td>
<td class='chardisp'><button value='Â' id='charInput' class='charbutt' onclick=\"copyFunction\">Â</button></td>
<td class='chardisp'><button value='Ã' id='charInput' class='charbutt' onclick=\"copyFunction\">Ã</button></td>
<td class='chardisp'><button value='Ä' id='charInput' class='charbutt' onclick=\"copyFunction\">Ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='à' id='charInput' class='charbutt' onclick=\"copyFunction\">à</button></td>
<td class='chardisp'><button value='á' id='charInput' class='charbutt' onclick=\"copyFunction\">á</button></td>
<td class='chardisp'><button value='â' id='charInput' class='charbutt' onclick=\"copyFunction\">â</button></td>
<td class='chardisp'><button value='ã' id='charInput' class='charbutt' onclick=\"copyFunction\">ã</button></td>
<td class='chardisp'><button value='ä' id='charInput' class='charbutt' onclick=\"copyFunction\">ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ç' id='charInput' class='charbutt' onclick=\"copyFunction\">Ç</button></td>
<td class='chardisp'><button value='ç' id='charInput' class='charbutt' onclick=\"copyFunction\">ç</button></td>
<td class='chardisp'><button value='È' id='charInput' class='charbutt' onclick=\"copyFunction\">È</button></td>
<td class='chardisp'><button value='É' id='charInput' class='charbutt' onclick=\"copyFunction\">É</button></td>
<td class='chardisp'><button value='Ê' id='charInput' class='charbutt' onclick=\"copyFunction\">Ê</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ë' id='charInput' class='charbutt' onclick=\"copyFunction\">Ë</button></td>
<td class='chardisp'><button value='è' id='charInput' class='charbutt' onclick=\"copyFunction\">è</button></td>
<td class='chardisp'><button value='é' id='charInput' class='charbutt' onclick=\"copyFunction\">é</button></td>
<td class='chardisp'><button value='ê' id='charInput' class='charbutt' onclick=\"copyFunction\">ê</button></td>
<td class='chardisp'><button value='ë' id='charInput' class='charbutt' onclick=\"copyFunction\">ë</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ì' id='charInput' class='charbutt' onclick=\"copyFunction\">Ì</button></td>
<td class='chardisp'><button value='Í' id='charInput' class='charbutt' onclick=\"copyFunction\">Í</button></td>
<td class='chardisp'><button value='Î' id='charInput' class='charbutt' onclick=\"copyFunction\">Î</button></td>
<td class='chardisp'><button value='Ï' id='charInput' class='charbutt' onclick=\"copyFunction\">Ï</button></td>
<td class='chardisp'><button value='ì' id='charInput' class='charbutt' onclick=\"copyFunction\">ì</button></td>
</tr>
<tr>
<td class='chardisp'><button value='í' id='charInput' class='charbutt' onclick=\"copyFunction\">í</button></td>
<td class='chardisp'><button value='î' id='charInput' class='charbutt' onclick=\"copyFunction\">î</button></td>
<td class='chardisp'><button value='ï' id='charInput' class='charbutt' onclick=\"copyFunction\">ï</button></td>
<td class='chardisp'><button value='Ò' id='charInput' class='charbutt' onclick=\"copyFunction\">Ò</button></td>
<td class='chardisp'><button value='Ó' id='charInput' class='charbutt' onclick=\"copyFunction\">Ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ô' id='charInput' class='charbutt' onclick=\"copyFunction\">Ô</button></td>
<td class='chardisp'><button value='Õ' id='charInput' class='charbutt' onclick=\"copyFunction\">Õ</button></td>
<td class='chardisp'><button value='Ö' id='charInput' class='charbutt' onclick=\"copyFunction\">Ö</button></td>
<td class='chardisp'><button value='ò' id='charInput' class='charbutt' onclick=\"copyFunction\">ò</button></td>
<td class='chardisp'><button value='ó' id='charInput' class='charbutt' onclick=\"copyFunction\">ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='ô' id='charInput' class='charbutt' onclick=\"copyFunction\">ô</button></td>
<td class='chardisp'><button value='õ' id='charInput' class='charbutt' onclick=\"copyFunction\">õ</button></td>
<td class='chardisp'><button value='ö' id='charInput' class='charbutt' onclick=\"copyFunction\">ö</button></td>
<td class='chardisp'><button value='Ù' id='charInput' class='charbutt' onclick=\"copyFunction\">Ù</button></td>
<td class='chardisp'><button value='Ú' id='charInput' class='charbutt' onclick=\"copyFunction\">Ú</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Û' id='charInput' class='charbutt' onclick=\"copyFunction\">Û</button></td>
<td class='chardisp'><button value='Ü' id='charInput' class='charbutt' onclick=\"copyFunction\">Ü</button></td>
<td class='chardisp'><button value='ù' id='charInput' class='charbutt' onclick=\"copyFunction\">ù</button></td>
<td class='chardisp'><button value='ú' id='charInput' class='charbutt' onclick=\"copyFunction\">ú</button></td>
<td class='chardisp'><button value='û' id='charInput' class='charbutt' onclick=\"copyFunction\">û</button></td>
</tr>
<tr>
<td class='chardisp'><button value='ü' id='charInput' class='charbutt' onclick=\"copyFunction\">ü</button></td>
<td class='chardisp'><button value='Ý' id='charInput' class='charbutt' onclick=\"copyFunction\">Ý</button></td>
<td class='chardisp'><button value='Ÿ' id='charInput' class='charbutt' onclick=\"copyFunction\">Ÿ</button></td>
<td class='chardisp'><button value='ý' id='charInput' class='charbutt' onclick=\"copyFunction\">ý</button></td>
<td class='chardisp'><button value='ÿ' id='charInput' class='charbutt' onclick=\"copyFunction\">ÿ</button></td>
</tr>
<tr>
</table>
</body>
</html>
如有任何帮助,我们将不胜感激。我知道这很简单,但对 Javascript 不是很好,我不知道从哪里开始!
元素 ID 应该是唯一的。
然而,要复制获取按钮值,您需要将 onclick 更改为以下示例
<td class='chardisp'><button value='<b>' id='charInput' class='charbutt' onclick="copyFunction(this)"><b></button></td>
这将允许函数获取元素的属性。
该函数也需要修改以适应,您将需要进一步研究如何使用 copyText 变量来为您工作。
示例:
function copyFunction(element) {
let elementValue = element.value
navigator.clipboard.writeText(elementValue);
}
为了更好地实施此解决方案,您可以调用 window onload 事件侦听器并查找 table.
中关联的所有按钮
要继续这条路线,请为您的 table 提供一个标识符,在本示例中,我提供了 #clipboardTable
。这将允许使用 querySelectorAll
为我们的按钮添加点击事件侦听器,并允许在 HTML 文档中使用更清晰的代码,从而允许删除重复的 onclick="copyFunction(this)"
手动所有按钮。
Window 按钮的事件侦听器和单击事件侦听器
window.addEventListener("load", (e) => {
// Find all buttons
let buttons = document.querySelectorAll("#clipboardTable button");
buttons.forEach(button => {
// Add event listener to each button
button.addEventListener("click", event => {
copyFunction(event.target)
})
})
})
复制功能可能与之前完成的一样。
查看此工作片段以证明概念。
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>
<title>Text Formatting</title>
<script>
// Window on load event listener
window.addEventListener("load", (e) => {
// Find all buttons
let buttons = document.querySelectorAll("#clipboardTable button");
buttons.forEach(button => {
// Add event listener to each button
button.addEventListener("click", event => {
copyFunction(event.target)
})
})
})
function copyFunction(element) {
let elementValue = element.value
navigator.clipboard.writeText(elementValue);
}
</script>
<style>
body {
background-color: #309bbf;
}
.chardisp {
width: 70px;
text-align: center;
}
.charhead {
font-family: sans-serif;
font-size: 14px;
color: white;
}
.charbutt {
width: 100%;
background-color: white;
border: 1px solid white;
border-radius: 2px;
padding: 3px;
font-family: sans-serif;
font-size: 11px;
color: black;
outline: 0;
}
.charbutt:hover {
cursor: pointer;
}
</style>
</head>
<body>
<table id="clipboardTable" border='0'>
<tr>
<td colspan='5'><p class='charhead'>FORMATTING</p></td>
</tr>
<tr>
<td class='chardisp'><button value='<b>...</b>' class='charbutt' ><b></button></td>
<td class='chardisp'><button value='<i>...</i>' class='charbutt' ><i></button></td>
<td class='chardisp'><button value='<u>...</u>' class='charbutt' ><u></button></td>
<td class='chardisp'><button value='<b>[...]</b>' class='charbutt' ><b>[...]</b></button></td>
<td class='chardisp'><button value='<br/>' class='charbutt' ><br/></button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>SYMBOLS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='&trade;' class='charbutt' >™</button></td>
<td class='chardisp'><button value='&reg;' class='charbutt' >®</button></td>
<td class='chardisp'><button value='&#161;' class='charbutt' >¡</button></td>
<td class='chardisp'><button value='&#191;' class='charbutt' >¿</button></td>
<td class='chardisp'><button value='&#223;' class='charbutt' >ß</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&amp;' class='charbutt' >&</button></td>
<td class='chardisp'><button value='&quot;' class='charbutt' >"</button></td>
<td class='chardisp'><button value='&pound;' class='charbutt' >£</button></td>
<td class='chardisp'><button value='&euro;' class='charbutt' >€</button></td>
<td class='chardisp'><button value='&#36;' class='charbutt' >$</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#188;' class='charbutt' >¼</button></td>
<td class='chardisp'><button value='&#8531;' class='charbutt' >⅓</button></td>
<td class='chardisp'><button value='&#8532;' class='charbutt' >⅔</button></td>
<td class='chardisp'><button value='&#189;' class='charbutt' >½</button></td>
<td class='chardisp'><button value='&#190;' class='charbutt' >¾</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#58;' class='charbutt' >:</button></td>
<td class='chardisp'><button value='&#59;' class='charbutt' >;</button></td>
<td class='chardisp'><button value='&#9834;' class='charbutt' >♪</button></td>
<td class='chardisp'><button value='&#35;' class='charbutt' >#</button></td>
<td class='chardisp'><button value='&#47;' class='charbutt' >/</button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>ACCENTED CHARACTERS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='&#192;' class='charbutt' >À</button></td>
<td class='chardisp'><button value='&#193;' class='charbutt' >Á</button></td>
<td class='chardisp'><button value='&#194;' class='charbutt' >Â</button></td>
<td class='chardisp'><button value='&#195;' class='charbutt' >Ã</button></td>
<td class='chardisp'><button value='&#196;' class='charbutt' >Ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#224;' class='charbutt' >à</button></td>
<td class='chardisp'><button value='&#225;' class='charbutt' >á</button></td>
<td class='chardisp'><button value='&#226;' class='charbutt' >â</button></td>
<td class='chardisp'><button value='&#227;' class='charbutt' >ã</button></td>
<td class='chardisp'><button value='&#228;' class='charbutt' >ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#199;' class='charbutt' >Ç</button></td>
<td class='chardisp'><button value='&#231;' class='charbutt' >ç</button></td>
<td class='chardisp'><button value='&#200;' class='charbutt' >È</button></td>
<td class='chardisp'><button value='&#201;' class='charbutt' >É</button></td>
<td class='chardisp'><button value='&#202;' class='charbutt' >Ê</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#203;' class='charbutt' >Ë</button></td>
<td class='chardisp'><button value='&#232;' class='charbutt' >è</button></td>
<td class='chardisp'><button value='&#233;' class='charbutt' >é</button></td>
<td class='chardisp'><button value='&#234;' class='charbutt' >ê</button></td>
<td class='chardisp'><button value='&#235;' class='charbutt' >ë</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#204;' class='charbutt' >Ì</button></td>
<td class='chardisp'><button value='&#205;' class='charbutt' >Í</button></td>
<td class='chardisp'><button value='&#206;' class='charbutt' >Î</button></td>
<td class='chardisp'><button value='&#207;' class='charbutt' >Ï</button></td>
<td class='chardisp'><button value='&#236;' class='charbutt' >ì</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#237;' class='charbutt' >í</button></td>
<td class='chardisp'><button value='&#238;' class='charbutt' >î</button></td>
<td class='chardisp'><button value='&#239;' class='charbutt' >ï</button></td>
<td class='chardisp'><button value='&#210;' class='charbutt' >Ò</button></td>
<td class='chardisp'><button value='&#211;' class='charbutt' >Ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#212;' class='charbutt' >Ô</button></td>
<td class='chardisp'><button value='&#213;' class='charbutt' >Õ</button></td>
<td class='chardisp'><button value='&#214;' class='charbutt' >Ö</button></td>
<td class='chardisp'><button value='&#242;' class='charbutt' >ò</button></td>
<td class='chardisp'><button value='&#243;' class='charbutt' >ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#244;' class='charbutt' >ô</button></td>
<td class='chardisp'><button value='&#245;' class='charbutt' >õ</button></td>
<td class='chardisp'><button value='&#246;' class='charbutt' >ö</button></td>
<td class='chardisp'><button value='&#217;' class='charbutt' >Ù</button></td>
<td class='chardisp'><button value='&#218;' class='charbutt' >Ú</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#219;' class='charbutt' >Û</button></td>
<td class='chardisp'><button value='&#220;' class='charbutt' >Ü</button></td>
<td class='chardisp'><button value='&#249;' class='charbutt' >ù</button></td>
<td class='chardisp'><button value='&#250;' class='charbutt' >ú</button></td>
<td class='chardisp'><button value='&#251;' class='charbutt' >û</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#252;' class='charbutt' >ü</button></td>
<td class='chardisp'><button value='&#221;' class='charbutt' >Ý</button></td>
<td class='chardisp'><button value='&#159;' class='charbutt' >Ÿ</button></td>
<td class='chardisp'><button value='&#253;' class='charbutt' >ý</button></td>
<td class='chardisp'><button value='&#255;' class='charbutt' >ÿ</button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>INPUT TEST</p></td>
</tr>
<tr>
<td colspan='5'><textarea style='width: 100%'></textarea></td>
</tr>
</table>
</body>
</html>
首先正确定义 onlick 函数,而不是通过 id 获取元素,将元素作为引用传递给函数,这将消除为每个元素分配 id 的负担,并删除不必要的代码。
最后 navigator.clipboard.writeText returns 一个 promise,因此应该正确使用它,否则它容易出错(即它会在第一次运行但如果您尝试复制另一个文本会抛出错误)
<script>
function copyFunction(e) {
navigator.clipboard.writeText(e.value).then(function() {
/* clipboard successfully set */
}, function() {
/* clipboard write failed */
});
}
</script>
<table border="0">
<tr>
<td colspan="5"><p class='charhead'>FORMATTING</p></td>
</tr>
<tr>
<td class='chardisp'><input type="button" value='<b>' id='charInput' class='charbutt' onclick=copyFunction(this)></input></td>
<td class='chardisp'><button value='<i>' id='charInput' class='charbutt' onclick=copyFunction(this)><i></button></td>
<td class='chardisp'><button value='<u>' id='charInput' class='charbutt' onclick=copyFunction(this)><u></button></td>
<td class='chardisp'><button value='<b>[ ... ]</b>' id='charInput' class='charbutt' onclick=copyFunction(this)><b>[ ... ]</b></button></td>
<td class='chardisp'><button value='<br/>' id='charInput' class='charbutt' onclick=copyFunction(this)><br/></button></td>
</tr>
<tr>
<td colspan="5"><p class='charhead'>SYMBOLS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='™' id='charInput' class='charbutt' onclick=copyFunction(this)>™</button></td>
<td class='chardisp'><button value='®' id='charInput' class='charbutt' onclick=copyFunction(this)>®</button></td>
<td class='chardisp'><button value='¡' id='charInput' class='charbutt' onclick=copyFunction(this)>¡</button></td>
<td class='chardisp'><button value='¿' id='charInput' class='charbutt' onclick=copyFunction(this)>¿</button></td>
<td class='chardisp'><button value='ß' id='charInput' class='charbutt' onclick=copyFunction(this)>ß</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&' id='charInput' class='charbutt' onclick=copyFunction(this)>&</button></td>
<td class='chardisp'><button value='$quot;' id='charInput' class='charbutt' onclick=copyFunction(this)>"</button></td>
<td class='chardisp'><button value='£' id='charInput' class='charbutt' onclick=copyFunction(this)>£</button></td>
<td class='chardisp'><button value='€' id='charInput' class='charbutt' onclick=copyFunction(this)>€</button></td>
<td class='chardisp'><button value='$' id='charInput' class='charbutt' onclick=copyFunction(this)>$</button></td>
</tr>
<tr>
<td class='chardisp'><button value='¼' id='charInput' class='charbutt' onclick=copyFunction(this)>¼</button></td>
<td class='chardisp'><button value='⅓' id='charInput' class='charbutt' onclick=copyFunction(this)>⅓</button></td>
<td class='chardisp'><button value='⅔' id='charInput' class='charbutt' onclick=copyFunction(this)>⅔</button></td>
<td class='chardisp'><button value='½' id='charInput' class='charbutt' onclick=copyFunction(this)>½</button></td>
<td class='chardisp'><button value='¾' id='charInput' class='charbutt' onclick=copyFunction(this)>¾</button></td>
</tr>
<tr>
<td class='chardisp'><button value=':' id='charInput' class='charbutt' onclick=copyFunction(this)>:</button></td>
<td class='chardisp'><button value=';' id='charInput' class='charbutt' onclick=copyFunction(this)>;</button></td>
<td class='chardisp'><button value='♪' id='charInput' class='charbutt' onclick=copyFunction(this)>♪</button></td>
<td class='chardisp'><button value='#' id='charInput' class='charbutt' onclick=copyFunction(this)>#</button></td>
<td class='chardisp'><button value='/' id='charInput' class='charbutt' onclick=copyFunction(this)>/</button></td>
</tr>
<tr>
<td colspan="5"><p class='charhead'>ACCENTED CHARACTERS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='À' id='charInput' class='charbutt' onclick=copyFunction(this)>À</button></td>
<td class='chardisp'><button value='Á' id='charInput' class='charbutt' onclick=copyFunction(this)>Á</button></td>
<td class='chardisp'><button value='Â' id='charInput' class='charbutt' onclick=copyFunction(this)>Â</button></td>
<td class='chardisp'><button value='Ã' id='charInput' class='charbutt' onclick=copyFunction(this)>Ã</button></td>
<td class='chardisp'><button value='Ä' id='charInput' class='charbutt' onclick=copyFunction(this)>Ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='à' id='charInput' class='charbutt' onclick=copyFunction(this)>à</button></td>
<td class='chardisp'><button value='á' id='charInput' class='charbutt' onclick=copyFunction(this)>á</button></td>
<td class='chardisp'><button value='â' id='charInput' class='charbutt' onclick=copyFunction(this)>â</button></td>
<td class='chardisp'><button value='ã' id='charInput' class='charbutt' onclick=copyFunction(this)>ã</button></td>
<td class='chardisp'><button value='ä' id='charInput' class='charbutt' onclick=copyFunction(this)>ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ç' id='charInput' class='charbutt' onclick=copyFunction(this)>Ç</button></td>
<td class='chardisp'><button value='ç' id='charInput' class='charbutt' onclick=copyFunction(this)>ç</button></td>
<td class='chardisp'><button value='È' id='charInput' class='charbutt' onclick=copyFunction(this)>È</button></td>
<td class='chardisp'><button value='É' id='charInput' class='charbutt' onclick=copyFunction(this)>É</button></td>
<td class='chardisp'><button value='Ê' id='charInput' class='charbutt' onclick=copyFunction(this)>Ê</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ë' id='charInput' class='charbutt' onclick=copyFunction(this)>Ë</button></td>
<td class='chardisp'><button value='è' id='charInput' class='charbutt' onclick=copyFunction(this)>è</button></td>
<td class='chardisp'><button value='é' id='charInput' class='charbutt' onclick=copyFunction(this)>é</button></td>
<td class='chardisp'><button value='ê' id='charInput' class='charbutt' onclick=copyFunction(this)>ê</button></td>
<td class='chardisp'><button value='ë' id='charInput' class='charbutt' onclick=copyFunction(this)>ë</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ì' id='charInput' class='charbutt' onclick=copyFunction(this)>Ì</button></td>
<td class='chardisp'><button value='Í' id='charInput' class='charbutt' onclick=copyFunction(this)>Í</button></td>
<td class='chardisp'><button value='Î' id='charInput' class='charbutt' onclick=copyFunction(this)>Î</button></td>
<td class='chardisp'><button value='Ï' id='charInput' class='charbutt' onclick=copyFunction(this)>Ï</button></td>
<td class='chardisp'><button value='ì' id='charInput' class='charbutt' onclick=copyFunction(this)>ì</button></td>
</tr>
<tr>
<td class='chardisp'><button value='í' id='charInput' class='charbutt' onclick=copyFunction(this)>í</button></td>
<td class='chardisp'><button value='î' id='charInput' class='charbutt' onclick=copyFunction(this)>î</button></td>
<td class='chardisp'><button value='ï' id='charInput' class='charbutt' onclick=copyFunction(this)>ï</button></td>
<td class='chardisp'><button value='Ò' id='charInput' class='charbutt' onclick=copyFunction(this)>Ò</button></td>
<td class='chardisp'><button value='Ó' id='charInput' class='charbutt' onclick=copyFunction(this)>Ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ô' id='charInput' class='charbutt' onclick=copyFunction(this)>Ô</button></td>
<td class='chardisp'><button value='Õ' id='charInput' class='charbutt' onclick=copyFunction(this)>Õ</button></td>
<td class='chardisp'><button value='Ö' id='charInput' class='charbutt' onclick=copyFunction(this)>Ö</button></td>
<td class='chardisp'><button value='ò' id='charInput' class='charbutt' onclick=copyFunction(this)>ò</button></td>
<td class='chardisp'><button value='ó' id='charInput' class='charbutt' onclick=copyFunction(this)>ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='ô' id='charInput' class='charbutt' onclick=copyFunction(this)>ô</button></td>
<td class='chardisp'><button value='õ' id='charInput' class='charbutt' onclick=copyFunction(this)>õ</button></td>
<td class='chardisp'><button value='ö' id='charInput' class='charbutt' onclick=copyFunction(this)>ö</button></td>
<td class='chardisp'><button value='Ù' id='charInput' class='charbutt' onclick=copyFunction(this)>Ù</button></td>
<td class='chardisp'><button value='Ú' id='charInput' class='charbutt' onclick=copyFunction(this)>Ú</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Û' id='charInput' class='charbutt' onclick=copyFunction(this)>Û</button></td>
<td class='chardisp'><button value='Ü' id='charInput' class='charbutt' onclick=copyFunction(this)>Ü</button></td>
<td class='chardisp'><button value='ù' id='charInput' class='charbutt' onclick=copyFunction(this)>ù</button></td>
<td class='chardisp'><button value='ú' id='charInput' class='charbutt' onclick=copyFunction(this)>ú</button></td>
<td class='chardisp'><button value='û' id='charInput' class='charbutt' onclick=copyFunction(this)>û</button></td>
</tr>
<tr>
<td class='chardisp'><button value='ü' id='charInput' class='charbutt' onclick=copyFunction(this)>ü</button></td>
<td class='chardisp'><button value='Ý' id='charInput' class='charbutt' onclick=copyFunction(this)>Ý</button></td>
<td class='chardisp'><button value='Ÿ' id='charInput' class='charbutt' onclick=copyFunction(this)>Ÿ</button></td>
<td class='chardisp'><button value='ý' id='charInput' class='charbutt' onclick=copyFunction(this)>ý</button></td>
<td class='chardisp'><button value='ÿ' id='charInput' class='charbutt' onclick=copyFunction(this)>ÿ</button></td>
</tr>
<tr>
</table>
我要感谢所有回复的人。当我意识到我错得多么严重时,那真是一个面面相觑的时刻!
最后,我选择了 Aidan 的回答,因为它允许我用实际字符格式化按钮,同时给出我需要复制的 HTML 代码的值,以确保它与 PHP 它被送入。对于我的特定问题,按钮标签在这方面远远胜过输入标签。
这是完全修改后的代码,如果其他人需要类似的东西,他们就不需要再问这么愚蠢的问题了!
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>
<title>Text Formatting</title>
<script>
function copyFunction(element) {
let elementValue = element.value
navigator.clipboard.writeText(elementValue);
}
</script>
<style>
body {
background-color: #309bbf;
}
.chardisp {
width: 70px;
text-align: center;
}
.charhead {
font-family: sans-serif;
font-size: 14px;
color: white;
}
.charbutt {
width: 100%;
background-color: white;
border: 1px solid white;
border-radius: 2px;
padding: 3px;
font-family: sans-serif;
font-size: 11px;
color: black;
outline: 0;
}
.charbutt:hover {
cursor: pointer;
}
</style>
</head>
<body>
<table border='0'>
<tr>
<td colspan='5'><p class='charhead'>FORMATTING</p></td>
</tr>
<tr>
<td class='chardisp'><button value='<b>...</b>' class='charbutt' onclick=copyFunction(this)><b></button></td>
<td class='chardisp'><button value='<i>...</i>' class='charbutt' onclick=copyFunction(this)><i></button></td>
<td class='chardisp'><button value='<u>...</u>' class='charbutt' onclick=copyFunction(this)><u></button></td>
<td class='chardisp'><button value='<b>[...]</b>' class='charbutt' onclick=copyFunction(this)><b>[...]</b></button></td>
<td class='chardisp'><button value='<br/>' class='charbutt' onclick=copyFunction(this)><br/></button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>SYMBOLS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='&trade;' class='charbutt' onclick=copyFunction(this)>™</button></td>
<td class='chardisp'><button value='&reg;' class='charbutt' onclick=copyFunction(this)>®</button></td>
<td class='chardisp'><button value='&#161;' class='charbutt' onclick=copyFunction(this)>¡</button></td>
<td class='chardisp'><button value='&#191;' class='charbutt' onclick=copyFunction(this)>¿</button></td>
<td class='chardisp'><button value='&#223;' class='charbutt' onclick=copyFunction(this)>ß</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&amp;' class='charbutt' onclick=copyFunction(this)>&</button></td>
<td class='chardisp'><button value='&quot;' class='charbutt' onclick=copyFunction(this)>"</button></td>
<td class='chardisp'><button value='&pound;' class='charbutt' onclick=copyFunction(this)>£</button></td>
<td class='chardisp'><button value='&euro;' class='charbutt' onclick=copyFunction(this)>€</button></td>
<td class='chardisp'><button value='&#36;' class='charbutt' onclick=copyFunction(this)>$</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#188;' class='charbutt' onclick=copyFunction(this)>¼</button></td>
<td class='chardisp'><button value='&#8531;' class='charbutt' onclick=copyFunction(this)>⅓</button></td>
<td class='chardisp'><button value='&#8532;' class='charbutt' onclick=copyFunction(this)>⅔</button></td>
<td class='chardisp'><button value='&#189;' class='charbutt' onclick=copyFunction(this)>½</button></td>
<td class='chardisp'><button value='&#190;' class='charbutt' onclick=copyFunction(this)>¾</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#58;' class='charbutt' onclick=copyFunction(this)>:</button></td>
<td class='chardisp'><button value='&#59;' class='charbutt' onclick=copyFunction(this)>;</button></td>
<td class='chardisp'><button value='&#9834;' class='charbutt' onclick=copyFunction(this)>♪</button></td>
<td class='chardisp'><button value='&#35;' class='charbutt' onclick=copyFunction(this)>#</button></td>
<td class='chardisp'><button value='&#47;' class='charbutt' onclick=copyFunction(this)>/</button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>ACCENTED CHARACTERS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='&#192;' class='charbutt' onclick=copyFunction(this)>À</button></td>
<td class='chardisp'><button value='&#193;' class='charbutt' onclick=copyFunction(this)>Á</button></td>
<td class='chardisp'><button value='&#194;' class='charbutt' onclick=copyFunction(this)>Â</button></td>
<td class='chardisp'><button value='&#195;' class='charbutt' onclick=copyFunction(this)>Ã</button></td>
<td class='chardisp'><button value='&#196;' class='charbutt' onclick=copyFunction(this)>Ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#224;' class='charbutt' onclick=copyFunction(this)>à</button></td>
<td class='chardisp'><button value='&#225;' class='charbutt' onclick=copyFunction(this)>á</button></td>
<td class='chardisp'><button value='&#226;' class='charbutt' onclick=copyFunction(this)>â</button></td>
<td class='chardisp'><button value='&#227;' class='charbutt' onclick=copyFunction(this)>ã</button></td>
<td class='chardisp'><button value='&#228;' class='charbutt' onclick=copyFunction(this)>ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#199;' class='charbutt' onclick=copyFunction(this)>Ç</button></td>
<td class='chardisp'><button value='&#231;' class='charbutt' onclick=copyFunction(this)>ç</button></td>
<td class='chardisp'><button value='&#200;' class='charbutt' onclick=copyFunction(this)>È</button></td>
<td class='chardisp'><button value='&#201;' class='charbutt' onclick=copyFunction(this)>É</button></td>
<td class='chardisp'><button value='&#202;' class='charbutt' onclick=copyFunction(this)>Ê</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#203;' class='charbutt' onclick=copyFunction(this)>Ë</button></td>
<td class='chardisp'><button value='&#232;' class='charbutt' onclick=copyFunction(this)>è</button></td>
<td class='chardisp'><button value='&#233;' class='charbutt' onclick=copyFunction(this)>é</button></td>
<td class='chardisp'><button value='&#234;' class='charbutt' onclick=copyFunction(this)>ê</button></td>
<td class='chardisp'><button value='&#235;' class='charbutt' onclick=copyFunction(this)>ë</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#204;' class='charbutt' onclick=copyFunction(this)>Ì</button></td>
<td class='chardisp'><button value='&#205;' class='charbutt' onclick=copyFunction(this)>Í</button></td>
<td class='chardisp'><button value='&#206;' class='charbutt' onclick=copyFunction(this)>Î</button></td>
<td class='chardisp'><button value='&#207;' class='charbutt' onclick=copyFunction(this)>Ï</button></td>
<td class='chardisp'><button value='&#236;' class='charbutt' onclick=copyFunction(this)>ì</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#237;' class='charbutt' onclick=copyFunction(this)>í</button></td>
<td class='chardisp'><button value='&#238;' class='charbutt' onclick=copyFunction(this)>î</button></td>
<td class='chardisp'><button value='&#239;' class='charbutt' onclick=copyFunction(this)>ï</button></td>
<td class='chardisp'><button value='&#210;' class='charbutt' onclick=copyFunction(this)>Ò</button></td>
<td class='chardisp'><button value='&#211;' class='charbutt' onclick=copyFunction(this)>Ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#212;' class='charbutt' onclick=copyFunction(this)>Ô</button></td>
<td class='chardisp'><button value='&#213;' class='charbutt' onclick=copyFunction(this)>Õ</button></td>
<td class='chardisp'><button value='&#214;' class='charbutt' onclick=copyFunction(this)>Ö</button></td>
<td class='chardisp'><button value='&#242;' class='charbutt' onclick=copyFunction(this)>ò</button></td>
<td class='chardisp'><button value='&#243;' class='charbutt' onclick=copyFunction(this)>ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#244;' class='charbutt' onclick=copyFunction(this)>ô</button></td>
<td class='chardisp'><button value='&#245;' class='charbutt' onclick=copyFunction(this)>õ</button></td>
<td class='chardisp'><button value='&#246;' class='charbutt' onclick=copyFunction(this)>ö</button></td>
<td class='chardisp'><button value='&#217;' class='charbutt' onclick=copyFunction(this)>Ù</button></td>
<td class='chardisp'><button value='&#218;' class='charbutt' onclick=copyFunction(this)>Ú</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#219;' class='charbutt' onclick=copyFunction(this)>Û</button></td>
<td class='chardisp'><button value='&#220;' class='charbutt' onclick=copyFunction(this)>Ü</button></td>
<td class='chardisp'><button value='&#249;' class='charbutt' onclick=copyFunction(this)>ù</button></td>
<td class='chardisp'><button value='&#250;' class='charbutt' onclick=copyFunction(this)>ú</button></td>
<td class='chardisp'><button value='&#251;' class='charbutt' onclick=copyFunction(this)>û</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#252;' class='charbutt' onclick=copyFunction(this)>ü</button></td>
<td class='chardisp'><button value='&#221;' class='charbutt' onclick=copyFunction(this)>Ý</button></td>
<td class='chardisp'><button value='&#159;' class='charbutt' onclick=copyFunction(this)>Ÿ</button></td>
<td class='chardisp'><button value='&#253;' class='charbutt' onclick=copyFunction(this)>ý</button></td>
<td class='chardisp'><button value='&#255;' class='charbutt' onclick=copyFunction(this)>ÿ</button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>INPUT TEST</p></td>
</tr>
<tr>
<td colspan='5'><textarea style='width: 100%'></textarea></td>
</tr>
</table>
</body>
</html>
如果可能的话,需要别人的一点帮助。
我正在为我的网站制作一个下拉菜单 DIV,它允许用户按下一个按钮并将各种符号的 HTML 字符代码复制到剪贴板。这还不是最终格式 - 我刚刚创建了一个简单的 HTML 页面来测试功能。
问题是它不起作用!我不确定我做错了什么。
这是我的 HTML,它结合了基本的内联样式表和 Javascript:
function copyFunction() {
/* Get the text field */
var copyText = document.getElementById("charInput");
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
/* Copy the text inside the text field */
navigator.clipboard.writeText(copyText.value);
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Text Formatting</title>
<style>
body {
background-color: #309bbf;
}
.chardisp {
width: 40px;
text-align: center;
}
.charhead {
font-family: sans-serif;
font-size: 14px;
color: white;
}
.charbutt {
width: 100%;
background-color: white;
border-radius: 2px;
padding: 3px;
font-family: sans-serif;
font-size: 11px;
color: black;
outline: 0;
}
.charbutt:hover {
cursor: pointer;
}
</style>
</head>
<body>
<table border="0">
<tr>
<td colspan="5"><p class='charhead'>FORMATTING</p></td>
</tr>
<tr>
<td class='chardisp'><button value='<b>' id='charInput' class='charbutt' onclick=\"copyFunction\"><b></button></td>
<td class='chardisp'><button value='<i>' id='charInput' class='charbutt' onclick=\"copyFunction\"><i></button></td>
<td class='chardisp'><button value='<u>' id='charInput' class='charbutt' onclick=\"copyFunction\"><u></button></td>
<td class='chardisp'><button value='<b>[ ... ]</b>' id='charInput' class='charbutt' onclick=\"copyFunction\"><b>[ ... ]</b></button></td>
<td class='chardisp'><button value='<br/>' id='charInput' class='charbutt' onclick=\"copyFunction\"><br/></button></td>
</tr>
<tr>
<td colspan="5"><p class='charhead'>SYMBOLS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='™' id='charInput' class='charbutt' onclick=\"copyFunction\">™</button></td>
<td class='chardisp'><button value='®' id='charInput' class='charbutt' onclick=\"copyFunction\">®</button></td>
<td class='chardisp'><button value='¡' id='charInput' class='charbutt' onclick=\"copyFunction\">¡</button></td>
<td class='chardisp'><button value='¿' id='charInput' class='charbutt' onclick=\"copyFunction\">¿</button></td>
<td class='chardisp'><button value='ß' id='charInput' class='charbutt' onclick=\"copyFunction\">ß</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&' id='charInput' class='charbutt' onclick=\"copyFunction\">&</button></td>
<td class='chardisp'><button value='$quot;' id='charInput' class='charbutt' onclick=\"copyFunction\">"</button></td>
<td class='chardisp'><button value='£' id='charInput' class='charbutt' onclick=\"copyFunction\">£</button></td>
<td class='chardisp'><button value='€' id='charInput' class='charbutt' onclick=\"copyFunction\">€</button></td>
<td class='chardisp'><button value='$' id='charInput' class='charbutt' onclick=\"copyFunction\">$</button></td>
</tr>
<tr>
<td class='chardisp'><button value='¼' id='charInput' class='charbutt' onclick=\"copyFunction\">¼</button></td>
<td class='chardisp'><button value='⅓' id='charInput' class='charbutt' onclick=\"copyFunction\">⅓</button></td>
<td class='chardisp'><button value='⅔' id='charInput' class='charbutt' onclick=\"copyFunction\">⅔</button></td>
<td class='chardisp'><button value='½' id='charInput' class='charbutt' onclick=\"copyFunction\">½</button></td>
<td class='chardisp'><button value='¾' id='charInput' class='charbutt' onclick=\"copyFunction\">¾</button></td>
</tr>
<tr>
<td class='chardisp'><button value=':' id='charInput' class='charbutt' onclick=\"copyFunction\">:</button></td>
<td class='chardisp'><button value=';' id='charInput' class='charbutt' onclick=\"copyFunction\">;</button></td>
<td class='chardisp'><button value='♪' id='charInput' class='charbutt' onclick=\"copyFunction\">♪</button></td>
<td class='chardisp'><button value='#' id='charInput' class='charbutt' onclick=\"copyFunction\">#</button></td>
<td class='chardisp'><button value='/' id='charInput' class='charbutt' onclick=\"copyFunction\">/</button></td>
</tr>
<tr>
<td colspan="5"><p class='charhead'>ACCENTED CHARACTERS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='À' id='charInput' class='charbutt' onclick=\"copyFunction\">À</button></td>
<td class='chardisp'><button value='Á' id='charInput' class='charbutt' onclick=\"copyFunction\">Á</button></td>
<td class='chardisp'><button value='Â' id='charInput' class='charbutt' onclick=\"copyFunction\">Â</button></td>
<td class='chardisp'><button value='Ã' id='charInput' class='charbutt' onclick=\"copyFunction\">Ã</button></td>
<td class='chardisp'><button value='Ä' id='charInput' class='charbutt' onclick=\"copyFunction\">Ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='à' id='charInput' class='charbutt' onclick=\"copyFunction\">à</button></td>
<td class='chardisp'><button value='á' id='charInput' class='charbutt' onclick=\"copyFunction\">á</button></td>
<td class='chardisp'><button value='â' id='charInput' class='charbutt' onclick=\"copyFunction\">â</button></td>
<td class='chardisp'><button value='ã' id='charInput' class='charbutt' onclick=\"copyFunction\">ã</button></td>
<td class='chardisp'><button value='ä' id='charInput' class='charbutt' onclick=\"copyFunction\">ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ç' id='charInput' class='charbutt' onclick=\"copyFunction\">Ç</button></td>
<td class='chardisp'><button value='ç' id='charInput' class='charbutt' onclick=\"copyFunction\">ç</button></td>
<td class='chardisp'><button value='È' id='charInput' class='charbutt' onclick=\"copyFunction\">È</button></td>
<td class='chardisp'><button value='É' id='charInput' class='charbutt' onclick=\"copyFunction\">É</button></td>
<td class='chardisp'><button value='Ê' id='charInput' class='charbutt' onclick=\"copyFunction\">Ê</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ë' id='charInput' class='charbutt' onclick=\"copyFunction\">Ë</button></td>
<td class='chardisp'><button value='è' id='charInput' class='charbutt' onclick=\"copyFunction\">è</button></td>
<td class='chardisp'><button value='é' id='charInput' class='charbutt' onclick=\"copyFunction\">é</button></td>
<td class='chardisp'><button value='ê' id='charInput' class='charbutt' onclick=\"copyFunction\">ê</button></td>
<td class='chardisp'><button value='ë' id='charInput' class='charbutt' onclick=\"copyFunction\">ë</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ì' id='charInput' class='charbutt' onclick=\"copyFunction\">Ì</button></td>
<td class='chardisp'><button value='Í' id='charInput' class='charbutt' onclick=\"copyFunction\">Í</button></td>
<td class='chardisp'><button value='Î' id='charInput' class='charbutt' onclick=\"copyFunction\">Î</button></td>
<td class='chardisp'><button value='Ï' id='charInput' class='charbutt' onclick=\"copyFunction\">Ï</button></td>
<td class='chardisp'><button value='ì' id='charInput' class='charbutt' onclick=\"copyFunction\">ì</button></td>
</tr>
<tr>
<td class='chardisp'><button value='í' id='charInput' class='charbutt' onclick=\"copyFunction\">í</button></td>
<td class='chardisp'><button value='î' id='charInput' class='charbutt' onclick=\"copyFunction\">î</button></td>
<td class='chardisp'><button value='ï' id='charInput' class='charbutt' onclick=\"copyFunction\">ï</button></td>
<td class='chardisp'><button value='Ò' id='charInput' class='charbutt' onclick=\"copyFunction\">Ò</button></td>
<td class='chardisp'><button value='Ó' id='charInput' class='charbutt' onclick=\"copyFunction\">Ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ô' id='charInput' class='charbutt' onclick=\"copyFunction\">Ô</button></td>
<td class='chardisp'><button value='Õ' id='charInput' class='charbutt' onclick=\"copyFunction\">Õ</button></td>
<td class='chardisp'><button value='Ö' id='charInput' class='charbutt' onclick=\"copyFunction\">Ö</button></td>
<td class='chardisp'><button value='ò' id='charInput' class='charbutt' onclick=\"copyFunction\">ò</button></td>
<td class='chardisp'><button value='ó' id='charInput' class='charbutt' onclick=\"copyFunction\">ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='ô' id='charInput' class='charbutt' onclick=\"copyFunction\">ô</button></td>
<td class='chardisp'><button value='õ' id='charInput' class='charbutt' onclick=\"copyFunction\">õ</button></td>
<td class='chardisp'><button value='ö' id='charInput' class='charbutt' onclick=\"copyFunction\">ö</button></td>
<td class='chardisp'><button value='Ù' id='charInput' class='charbutt' onclick=\"copyFunction\">Ù</button></td>
<td class='chardisp'><button value='Ú' id='charInput' class='charbutt' onclick=\"copyFunction\">Ú</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Û' id='charInput' class='charbutt' onclick=\"copyFunction\">Û</button></td>
<td class='chardisp'><button value='Ü' id='charInput' class='charbutt' onclick=\"copyFunction\">Ü</button></td>
<td class='chardisp'><button value='ù' id='charInput' class='charbutt' onclick=\"copyFunction\">ù</button></td>
<td class='chardisp'><button value='ú' id='charInput' class='charbutt' onclick=\"copyFunction\">ú</button></td>
<td class='chardisp'><button value='û' id='charInput' class='charbutt' onclick=\"copyFunction\">û</button></td>
</tr>
<tr>
<td class='chardisp'><button value='ü' id='charInput' class='charbutt' onclick=\"copyFunction\">ü</button></td>
<td class='chardisp'><button value='Ý' id='charInput' class='charbutt' onclick=\"copyFunction\">Ý</button></td>
<td class='chardisp'><button value='Ÿ' id='charInput' class='charbutt' onclick=\"copyFunction\">Ÿ</button></td>
<td class='chardisp'><button value='ý' id='charInput' class='charbutt' onclick=\"copyFunction\">ý</button></td>
<td class='chardisp'><button value='ÿ' id='charInput' class='charbutt' onclick=\"copyFunction\">ÿ</button></td>
</tr>
<tr>
</table>
</body>
</html>
如有任何帮助,我们将不胜感激。我知道这很简单,但对 Javascript 不是很好,我不知道从哪里开始!
元素 ID 应该是唯一的。
然而,要复制获取按钮值,您需要将 onclick 更改为以下示例
<td class='chardisp'><button value='<b>' id='charInput' class='charbutt' onclick="copyFunction(this)"><b></button></td>
这将允许函数获取元素的属性。
该函数也需要修改以适应,您将需要进一步研究如何使用 copyText 变量来为您工作。
示例:
function copyFunction(element) {
let elementValue = element.value
navigator.clipboard.writeText(elementValue);
}
为了更好地实施此解决方案,您可以调用 window onload 事件侦听器并查找 table.
中关联的所有按钮要继续这条路线,请为您的 table 提供一个标识符,在本示例中,我提供了 #clipboardTable
。这将允许使用 querySelectorAll
为我们的按钮添加点击事件侦听器,并允许在 HTML 文档中使用更清晰的代码,从而允许删除重复的 onclick="copyFunction(this)"
手动所有按钮。
Window 按钮的事件侦听器和单击事件侦听器
window.addEventListener("load", (e) => {
// Find all buttons
let buttons = document.querySelectorAll("#clipboardTable button");
buttons.forEach(button => {
// Add event listener to each button
button.addEventListener("click", event => {
copyFunction(event.target)
})
})
})
复制功能可能与之前完成的一样。
查看此工作片段以证明概念。
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>
<title>Text Formatting</title>
<script>
// Window on load event listener
window.addEventListener("load", (e) => {
// Find all buttons
let buttons = document.querySelectorAll("#clipboardTable button");
buttons.forEach(button => {
// Add event listener to each button
button.addEventListener("click", event => {
copyFunction(event.target)
})
})
})
function copyFunction(element) {
let elementValue = element.value
navigator.clipboard.writeText(elementValue);
}
</script>
<style>
body {
background-color: #309bbf;
}
.chardisp {
width: 70px;
text-align: center;
}
.charhead {
font-family: sans-serif;
font-size: 14px;
color: white;
}
.charbutt {
width: 100%;
background-color: white;
border: 1px solid white;
border-radius: 2px;
padding: 3px;
font-family: sans-serif;
font-size: 11px;
color: black;
outline: 0;
}
.charbutt:hover {
cursor: pointer;
}
</style>
</head>
<body>
<table id="clipboardTable" border='0'>
<tr>
<td colspan='5'><p class='charhead'>FORMATTING</p></td>
</tr>
<tr>
<td class='chardisp'><button value='<b>...</b>' class='charbutt' ><b></button></td>
<td class='chardisp'><button value='<i>...</i>' class='charbutt' ><i></button></td>
<td class='chardisp'><button value='<u>...</u>' class='charbutt' ><u></button></td>
<td class='chardisp'><button value='<b>[...]</b>' class='charbutt' ><b>[...]</b></button></td>
<td class='chardisp'><button value='<br/>' class='charbutt' ><br/></button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>SYMBOLS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='&trade;' class='charbutt' >™</button></td>
<td class='chardisp'><button value='&reg;' class='charbutt' >®</button></td>
<td class='chardisp'><button value='&#161;' class='charbutt' >¡</button></td>
<td class='chardisp'><button value='&#191;' class='charbutt' >¿</button></td>
<td class='chardisp'><button value='&#223;' class='charbutt' >ß</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&amp;' class='charbutt' >&</button></td>
<td class='chardisp'><button value='&quot;' class='charbutt' >"</button></td>
<td class='chardisp'><button value='&pound;' class='charbutt' >£</button></td>
<td class='chardisp'><button value='&euro;' class='charbutt' >€</button></td>
<td class='chardisp'><button value='&#36;' class='charbutt' >$</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#188;' class='charbutt' >¼</button></td>
<td class='chardisp'><button value='&#8531;' class='charbutt' >⅓</button></td>
<td class='chardisp'><button value='&#8532;' class='charbutt' >⅔</button></td>
<td class='chardisp'><button value='&#189;' class='charbutt' >½</button></td>
<td class='chardisp'><button value='&#190;' class='charbutt' >¾</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#58;' class='charbutt' >:</button></td>
<td class='chardisp'><button value='&#59;' class='charbutt' >;</button></td>
<td class='chardisp'><button value='&#9834;' class='charbutt' >♪</button></td>
<td class='chardisp'><button value='&#35;' class='charbutt' >#</button></td>
<td class='chardisp'><button value='&#47;' class='charbutt' >/</button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>ACCENTED CHARACTERS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='&#192;' class='charbutt' >À</button></td>
<td class='chardisp'><button value='&#193;' class='charbutt' >Á</button></td>
<td class='chardisp'><button value='&#194;' class='charbutt' >Â</button></td>
<td class='chardisp'><button value='&#195;' class='charbutt' >Ã</button></td>
<td class='chardisp'><button value='&#196;' class='charbutt' >Ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#224;' class='charbutt' >à</button></td>
<td class='chardisp'><button value='&#225;' class='charbutt' >á</button></td>
<td class='chardisp'><button value='&#226;' class='charbutt' >â</button></td>
<td class='chardisp'><button value='&#227;' class='charbutt' >ã</button></td>
<td class='chardisp'><button value='&#228;' class='charbutt' >ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#199;' class='charbutt' >Ç</button></td>
<td class='chardisp'><button value='&#231;' class='charbutt' >ç</button></td>
<td class='chardisp'><button value='&#200;' class='charbutt' >È</button></td>
<td class='chardisp'><button value='&#201;' class='charbutt' >É</button></td>
<td class='chardisp'><button value='&#202;' class='charbutt' >Ê</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#203;' class='charbutt' >Ë</button></td>
<td class='chardisp'><button value='&#232;' class='charbutt' >è</button></td>
<td class='chardisp'><button value='&#233;' class='charbutt' >é</button></td>
<td class='chardisp'><button value='&#234;' class='charbutt' >ê</button></td>
<td class='chardisp'><button value='&#235;' class='charbutt' >ë</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#204;' class='charbutt' >Ì</button></td>
<td class='chardisp'><button value='&#205;' class='charbutt' >Í</button></td>
<td class='chardisp'><button value='&#206;' class='charbutt' >Î</button></td>
<td class='chardisp'><button value='&#207;' class='charbutt' >Ï</button></td>
<td class='chardisp'><button value='&#236;' class='charbutt' >ì</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#237;' class='charbutt' >í</button></td>
<td class='chardisp'><button value='&#238;' class='charbutt' >î</button></td>
<td class='chardisp'><button value='&#239;' class='charbutt' >ï</button></td>
<td class='chardisp'><button value='&#210;' class='charbutt' >Ò</button></td>
<td class='chardisp'><button value='&#211;' class='charbutt' >Ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#212;' class='charbutt' >Ô</button></td>
<td class='chardisp'><button value='&#213;' class='charbutt' >Õ</button></td>
<td class='chardisp'><button value='&#214;' class='charbutt' >Ö</button></td>
<td class='chardisp'><button value='&#242;' class='charbutt' >ò</button></td>
<td class='chardisp'><button value='&#243;' class='charbutt' >ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#244;' class='charbutt' >ô</button></td>
<td class='chardisp'><button value='&#245;' class='charbutt' >õ</button></td>
<td class='chardisp'><button value='&#246;' class='charbutt' >ö</button></td>
<td class='chardisp'><button value='&#217;' class='charbutt' >Ù</button></td>
<td class='chardisp'><button value='&#218;' class='charbutt' >Ú</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#219;' class='charbutt' >Û</button></td>
<td class='chardisp'><button value='&#220;' class='charbutt' >Ü</button></td>
<td class='chardisp'><button value='&#249;' class='charbutt' >ù</button></td>
<td class='chardisp'><button value='&#250;' class='charbutt' >ú</button></td>
<td class='chardisp'><button value='&#251;' class='charbutt' >û</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#252;' class='charbutt' >ü</button></td>
<td class='chardisp'><button value='&#221;' class='charbutt' >Ý</button></td>
<td class='chardisp'><button value='&#159;' class='charbutt' >Ÿ</button></td>
<td class='chardisp'><button value='&#253;' class='charbutt' >ý</button></td>
<td class='chardisp'><button value='&#255;' class='charbutt' >ÿ</button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>INPUT TEST</p></td>
</tr>
<tr>
<td colspan='5'><textarea style='width: 100%'></textarea></td>
</tr>
</table>
</body>
</html>
首先正确定义 onlick 函数,而不是通过 id 获取元素,将元素作为引用传递给函数,这将消除为每个元素分配 id 的负担,并删除不必要的代码。 最后 navigator.clipboard.writeText returns 一个 promise,因此应该正确使用它,否则它容易出错(即它会在第一次运行但如果您尝试复制另一个文本会抛出错误)
<script>
function copyFunction(e) {
navigator.clipboard.writeText(e.value).then(function() {
/* clipboard successfully set */
}, function() {
/* clipboard write failed */
});
}
</script>
<table border="0">
<tr>
<td colspan="5"><p class='charhead'>FORMATTING</p></td>
</tr>
<tr>
<td class='chardisp'><input type="button" value='<b>' id='charInput' class='charbutt' onclick=copyFunction(this)></input></td>
<td class='chardisp'><button value='<i>' id='charInput' class='charbutt' onclick=copyFunction(this)><i></button></td>
<td class='chardisp'><button value='<u>' id='charInput' class='charbutt' onclick=copyFunction(this)><u></button></td>
<td class='chardisp'><button value='<b>[ ... ]</b>' id='charInput' class='charbutt' onclick=copyFunction(this)><b>[ ... ]</b></button></td>
<td class='chardisp'><button value='<br/>' id='charInput' class='charbutt' onclick=copyFunction(this)><br/></button></td>
</tr>
<tr>
<td colspan="5"><p class='charhead'>SYMBOLS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='™' id='charInput' class='charbutt' onclick=copyFunction(this)>™</button></td>
<td class='chardisp'><button value='®' id='charInput' class='charbutt' onclick=copyFunction(this)>®</button></td>
<td class='chardisp'><button value='¡' id='charInput' class='charbutt' onclick=copyFunction(this)>¡</button></td>
<td class='chardisp'><button value='¿' id='charInput' class='charbutt' onclick=copyFunction(this)>¿</button></td>
<td class='chardisp'><button value='ß' id='charInput' class='charbutt' onclick=copyFunction(this)>ß</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&' id='charInput' class='charbutt' onclick=copyFunction(this)>&</button></td>
<td class='chardisp'><button value='$quot;' id='charInput' class='charbutt' onclick=copyFunction(this)>"</button></td>
<td class='chardisp'><button value='£' id='charInput' class='charbutt' onclick=copyFunction(this)>£</button></td>
<td class='chardisp'><button value='€' id='charInput' class='charbutt' onclick=copyFunction(this)>€</button></td>
<td class='chardisp'><button value='$' id='charInput' class='charbutt' onclick=copyFunction(this)>$</button></td>
</tr>
<tr>
<td class='chardisp'><button value='¼' id='charInput' class='charbutt' onclick=copyFunction(this)>¼</button></td>
<td class='chardisp'><button value='⅓' id='charInput' class='charbutt' onclick=copyFunction(this)>⅓</button></td>
<td class='chardisp'><button value='⅔' id='charInput' class='charbutt' onclick=copyFunction(this)>⅔</button></td>
<td class='chardisp'><button value='½' id='charInput' class='charbutt' onclick=copyFunction(this)>½</button></td>
<td class='chardisp'><button value='¾' id='charInput' class='charbutt' onclick=copyFunction(this)>¾</button></td>
</tr>
<tr>
<td class='chardisp'><button value=':' id='charInput' class='charbutt' onclick=copyFunction(this)>:</button></td>
<td class='chardisp'><button value=';' id='charInput' class='charbutt' onclick=copyFunction(this)>;</button></td>
<td class='chardisp'><button value='♪' id='charInput' class='charbutt' onclick=copyFunction(this)>♪</button></td>
<td class='chardisp'><button value='#' id='charInput' class='charbutt' onclick=copyFunction(this)>#</button></td>
<td class='chardisp'><button value='/' id='charInput' class='charbutt' onclick=copyFunction(this)>/</button></td>
</tr>
<tr>
<td colspan="5"><p class='charhead'>ACCENTED CHARACTERS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='À' id='charInput' class='charbutt' onclick=copyFunction(this)>À</button></td>
<td class='chardisp'><button value='Á' id='charInput' class='charbutt' onclick=copyFunction(this)>Á</button></td>
<td class='chardisp'><button value='Â' id='charInput' class='charbutt' onclick=copyFunction(this)>Â</button></td>
<td class='chardisp'><button value='Ã' id='charInput' class='charbutt' onclick=copyFunction(this)>Ã</button></td>
<td class='chardisp'><button value='Ä' id='charInput' class='charbutt' onclick=copyFunction(this)>Ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='à' id='charInput' class='charbutt' onclick=copyFunction(this)>à</button></td>
<td class='chardisp'><button value='á' id='charInput' class='charbutt' onclick=copyFunction(this)>á</button></td>
<td class='chardisp'><button value='â' id='charInput' class='charbutt' onclick=copyFunction(this)>â</button></td>
<td class='chardisp'><button value='ã' id='charInput' class='charbutt' onclick=copyFunction(this)>ã</button></td>
<td class='chardisp'><button value='ä' id='charInput' class='charbutt' onclick=copyFunction(this)>ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ç' id='charInput' class='charbutt' onclick=copyFunction(this)>Ç</button></td>
<td class='chardisp'><button value='ç' id='charInput' class='charbutt' onclick=copyFunction(this)>ç</button></td>
<td class='chardisp'><button value='È' id='charInput' class='charbutt' onclick=copyFunction(this)>È</button></td>
<td class='chardisp'><button value='É' id='charInput' class='charbutt' onclick=copyFunction(this)>É</button></td>
<td class='chardisp'><button value='Ê' id='charInput' class='charbutt' onclick=copyFunction(this)>Ê</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ë' id='charInput' class='charbutt' onclick=copyFunction(this)>Ë</button></td>
<td class='chardisp'><button value='è' id='charInput' class='charbutt' onclick=copyFunction(this)>è</button></td>
<td class='chardisp'><button value='é' id='charInput' class='charbutt' onclick=copyFunction(this)>é</button></td>
<td class='chardisp'><button value='ê' id='charInput' class='charbutt' onclick=copyFunction(this)>ê</button></td>
<td class='chardisp'><button value='ë' id='charInput' class='charbutt' onclick=copyFunction(this)>ë</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ì' id='charInput' class='charbutt' onclick=copyFunction(this)>Ì</button></td>
<td class='chardisp'><button value='Í' id='charInput' class='charbutt' onclick=copyFunction(this)>Í</button></td>
<td class='chardisp'><button value='Î' id='charInput' class='charbutt' onclick=copyFunction(this)>Î</button></td>
<td class='chardisp'><button value='Ï' id='charInput' class='charbutt' onclick=copyFunction(this)>Ï</button></td>
<td class='chardisp'><button value='ì' id='charInput' class='charbutt' onclick=copyFunction(this)>ì</button></td>
</tr>
<tr>
<td class='chardisp'><button value='í' id='charInput' class='charbutt' onclick=copyFunction(this)>í</button></td>
<td class='chardisp'><button value='î' id='charInput' class='charbutt' onclick=copyFunction(this)>î</button></td>
<td class='chardisp'><button value='ï' id='charInput' class='charbutt' onclick=copyFunction(this)>ï</button></td>
<td class='chardisp'><button value='Ò' id='charInput' class='charbutt' onclick=copyFunction(this)>Ò</button></td>
<td class='chardisp'><button value='Ó' id='charInput' class='charbutt' onclick=copyFunction(this)>Ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Ô' id='charInput' class='charbutt' onclick=copyFunction(this)>Ô</button></td>
<td class='chardisp'><button value='Õ' id='charInput' class='charbutt' onclick=copyFunction(this)>Õ</button></td>
<td class='chardisp'><button value='Ö' id='charInput' class='charbutt' onclick=copyFunction(this)>Ö</button></td>
<td class='chardisp'><button value='ò' id='charInput' class='charbutt' onclick=copyFunction(this)>ò</button></td>
<td class='chardisp'><button value='ó' id='charInput' class='charbutt' onclick=copyFunction(this)>ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='ô' id='charInput' class='charbutt' onclick=copyFunction(this)>ô</button></td>
<td class='chardisp'><button value='õ' id='charInput' class='charbutt' onclick=copyFunction(this)>õ</button></td>
<td class='chardisp'><button value='ö' id='charInput' class='charbutt' onclick=copyFunction(this)>ö</button></td>
<td class='chardisp'><button value='Ù' id='charInput' class='charbutt' onclick=copyFunction(this)>Ù</button></td>
<td class='chardisp'><button value='Ú' id='charInput' class='charbutt' onclick=copyFunction(this)>Ú</button></td>
</tr>
<tr>
<td class='chardisp'><button value='Û' id='charInput' class='charbutt' onclick=copyFunction(this)>Û</button></td>
<td class='chardisp'><button value='Ü' id='charInput' class='charbutt' onclick=copyFunction(this)>Ü</button></td>
<td class='chardisp'><button value='ù' id='charInput' class='charbutt' onclick=copyFunction(this)>ù</button></td>
<td class='chardisp'><button value='ú' id='charInput' class='charbutt' onclick=copyFunction(this)>ú</button></td>
<td class='chardisp'><button value='û' id='charInput' class='charbutt' onclick=copyFunction(this)>û</button></td>
</tr>
<tr>
<td class='chardisp'><button value='ü' id='charInput' class='charbutt' onclick=copyFunction(this)>ü</button></td>
<td class='chardisp'><button value='Ý' id='charInput' class='charbutt' onclick=copyFunction(this)>Ý</button></td>
<td class='chardisp'><button value='Ÿ' id='charInput' class='charbutt' onclick=copyFunction(this)>Ÿ</button></td>
<td class='chardisp'><button value='ý' id='charInput' class='charbutt' onclick=copyFunction(this)>ý</button></td>
<td class='chardisp'><button value='ÿ' id='charInput' class='charbutt' onclick=copyFunction(this)>ÿ</button></td>
</tr>
<tr>
</table>
我要感谢所有回复的人。当我意识到我错得多么严重时,那真是一个面面相觑的时刻!
最后,我选择了 Aidan 的回答,因为它允许我用实际字符格式化按钮,同时给出我需要复制的 HTML 代码的值,以确保它与 PHP 它被送入。对于我的特定问题,按钮标签在这方面远远胜过输入标签。
这是完全修改后的代码,如果其他人需要类似的东西,他们就不需要再问这么愚蠢的问题了!
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>
<title>Text Formatting</title>
<script>
function copyFunction(element) {
let elementValue = element.value
navigator.clipboard.writeText(elementValue);
}
</script>
<style>
body {
background-color: #309bbf;
}
.chardisp {
width: 70px;
text-align: center;
}
.charhead {
font-family: sans-serif;
font-size: 14px;
color: white;
}
.charbutt {
width: 100%;
background-color: white;
border: 1px solid white;
border-radius: 2px;
padding: 3px;
font-family: sans-serif;
font-size: 11px;
color: black;
outline: 0;
}
.charbutt:hover {
cursor: pointer;
}
</style>
</head>
<body>
<table border='0'>
<tr>
<td colspan='5'><p class='charhead'>FORMATTING</p></td>
</tr>
<tr>
<td class='chardisp'><button value='<b>...</b>' class='charbutt' onclick=copyFunction(this)><b></button></td>
<td class='chardisp'><button value='<i>...</i>' class='charbutt' onclick=copyFunction(this)><i></button></td>
<td class='chardisp'><button value='<u>...</u>' class='charbutt' onclick=copyFunction(this)><u></button></td>
<td class='chardisp'><button value='<b>[...]</b>' class='charbutt' onclick=copyFunction(this)><b>[...]</b></button></td>
<td class='chardisp'><button value='<br/>' class='charbutt' onclick=copyFunction(this)><br/></button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>SYMBOLS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='&trade;' class='charbutt' onclick=copyFunction(this)>™</button></td>
<td class='chardisp'><button value='&reg;' class='charbutt' onclick=copyFunction(this)>®</button></td>
<td class='chardisp'><button value='&#161;' class='charbutt' onclick=copyFunction(this)>¡</button></td>
<td class='chardisp'><button value='&#191;' class='charbutt' onclick=copyFunction(this)>¿</button></td>
<td class='chardisp'><button value='&#223;' class='charbutt' onclick=copyFunction(this)>ß</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&amp;' class='charbutt' onclick=copyFunction(this)>&</button></td>
<td class='chardisp'><button value='&quot;' class='charbutt' onclick=copyFunction(this)>"</button></td>
<td class='chardisp'><button value='&pound;' class='charbutt' onclick=copyFunction(this)>£</button></td>
<td class='chardisp'><button value='&euro;' class='charbutt' onclick=copyFunction(this)>€</button></td>
<td class='chardisp'><button value='&#36;' class='charbutt' onclick=copyFunction(this)>$</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#188;' class='charbutt' onclick=copyFunction(this)>¼</button></td>
<td class='chardisp'><button value='&#8531;' class='charbutt' onclick=copyFunction(this)>⅓</button></td>
<td class='chardisp'><button value='&#8532;' class='charbutt' onclick=copyFunction(this)>⅔</button></td>
<td class='chardisp'><button value='&#189;' class='charbutt' onclick=copyFunction(this)>½</button></td>
<td class='chardisp'><button value='&#190;' class='charbutt' onclick=copyFunction(this)>¾</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#58;' class='charbutt' onclick=copyFunction(this)>:</button></td>
<td class='chardisp'><button value='&#59;' class='charbutt' onclick=copyFunction(this)>;</button></td>
<td class='chardisp'><button value='&#9834;' class='charbutt' onclick=copyFunction(this)>♪</button></td>
<td class='chardisp'><button value='&#35;' class='charbutt' onclick=copyFunction(this)>#</button></td>
<td class='chardisp'><button value='&#47;' class='charbutt' onclick=copyFunction(this)>/</button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>ACCENTED CHARACTERS</p></td>
</tr>
<tr>
<td class='chardisp'><button value='&#192;' class='charbutt' onclick=copyFunction(this)>À</button></td>
<td class='chardisp'><button value='&#193;' class='charbutt' onclick=copyFunction(this)>Á</button></td>
<td class='chardisp'><button value='&#194;' class='charbutt' onclick=copyFunction(this)>Â</button></td>
<td class='chardisp'><button value='&#195;' class='charbutt' onclick=copyFunction(this)>Ã</button></td>
<td class='chardisp'><button value='&#196;' class='charbutt' onclick=copyFunction(this)>Ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#224;' class='charbutt' onclick=copyFunction(this)>à</button></td>
<td class='chardisp'><button value='&#225;' class='charbutt' onclick=copyFunction(this)>á</button></td>
<td class='chardisp'><button value='&#226;' class='charbutt' onclick=copyFunction(this)>â</button></td>
<td class='chardisp'><button value='&#227;' class='charbutt' onclick=copyFunction(this)>ã</button></td>
<td class='chardisp'><button value='&#228;' class='charbutt' onclick=copyFunction(this)>ä</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#199;' class='charbutt' onclick=copyFunction(this)>Ç</button></td>
<td class='chardisp'><button value='&#231;' class='charbutt' onclick=copyFunction(this)>ç</button></td>
<td class='chardisp'><button value='&#200;' class='charbutt' onclick=copyFunction(this)>È</button></td>
<td class='chardisp'><button value='&#201;' class='charbutt' onclick=copyFunction(this)>É</button></td>
<td class='chardisp'><button value='&#202;' class='charbutt' onclick=copyFunction(this)>Ê</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#203;' class='charbutt' onclick=copyFunction(this)>Ë</button></td>
<td class='chardisp'><button value='&#232;' class='charbutt' onclick=copyFunction(this)>è</button></td>
<td class='chardisp'><button value='&#233;' class='charbutt' onclick=copyFunction(this)>é</button></td>
<td class='chardisp'><button value='&#234;' class='charbutt' onclick=copyFunction(this)>ê</button></td>
<td class='chardisp'><button value='&#235;' class='charbutt' onclick=copyFunction(this)>ë</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#204;' class='charbutt' onclick=copyFunction(this)>Ì</button></td>
<td class='chardisp'><button value='&#205;' class='charbutt' onclick=copyFunction(this)>Í</button></td>
<td class='chardisp'><button value='&#206;' class='charbutt' onclick=copyFunction(this)>Î</button></td>
<td class='chardisp'><button value='&#207;' class='charbutt' onclick=copyFunction(this)>Ï</button></td>
<td class='chardisp'><button value='&#236;' class='charbutt' onclick=copyFunction(this)>ì</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#237;' class='charbutt' onclick=copyFunction(this)>í</button></td>
<td class='chardisp'><button value='&#238;' class='charbutt' onclick=copyFunction(this)>î</button></td>
<td class='chardisp'><button value='&#239;' class='charbutt' onclick=copyFunction(this)>ï</button></td>
<td class='chardisp'><button value='&#210;' class='charbutt' onclick=copyFunction(this)>Ò</button></td>
<td class='chardisp'><button value='&#211;' class='charbutt' onclick=copyFunction(this)>Ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#212;' class='charbutt' onclick=copyFunction(this)>Ô</button></td>
<td class='chardisp'><button value='&#213;' class='charbutt' onclick=copyFunction(this)>Õ</button></td>
<td class='chardisp'><button value='&#214;' class='charbutt' onclick=copyFunction(this)>Ö</button></td>
<td class='chardisp'><button value='&#242;' class='charbutt' onclick=copyFunction(this)>ò</button></td>
<td class='chardisp'><button value='&#243;' class='charbutt' onclick=copyFunction(this)>ó</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#244;' class='charbutt' onclick=copyFunction(this)>ô</button></td>
<td class='chardisp'><button value='&#245;' class='charbutt' onclick=copyFunction(this)>õ</button></td>
<td class='chardisp'><button value='&#246;' class='charbutt' onclick=copyFunction(this)>ö</button></td>
<td class='chardisp'><button value='&#217;' class='charbutt' onclick=copyFunction(this)>Ù</button></td>
<td class='chardisp'><button value='&#218;' class='charbutt' onclick=copyFunction(this)>Ú</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#219;' class='charbutt' onclick=copyFunction(this)>Û</button></td>
<td class='chardisp'><button value='&#220;' class='charbutt' onclick=copyFunction(this)>Ü</button></td>
<td class='chardisp'><button value='&#249;' class='charbutt' onclick=copyFunction(this)>ù</button></td>
<td class='chardisp'><button value='&#250;' class='charbutt' onclick=copyFunction(this)>ú</button></td>
<td class='chardisp'><button value='&#251;' class='charbutt' onclick=copyFunction(this)>û</button></td>
</tr>
<tr>
<td class='chardisp'><button value='&#252;' class='charbutt' onclick=copyFunction(this)>ü</button></td>
<td class='chardisp'><button value='&#221;' class='charbutt' onclick=copyFunction(this)>Ý</button></td>
<td class='chardisp'><button value='&#159;' class='charbutt' onclick=copyFunction(this)>Ÿ</button></td>
<td class='chardisp'><button value='&#253;' class='charbutt' onclick=copyFunction(this)>ý</button></td>
<td class='chardisp'><button value='&#255;' class='charbutt' onclick=copyFunction(this)>ÿ</button></td>
</tr>
<tr>
<td colspan='5'><p class='charhead'>INPUT TEST</p></td>
</tr>
<tr>
<td colspan='5'><textarea style='width: 100%'></textarea></td>
</tr>
</table>
</body>
</html>