onclick 属性由元素上的鼠标点击触发。
onclick 属性不适用以下元素:<base>、<bdo>、<br>、<head>、<html>、<iframe>、<meta>、<script>、<style> 或<title>。
<element onclick="script">
| 参数 | 描述 |
| script | onclick 发生时运行的脚本。 |
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>鱼C-零基础入门学习Web(Html5+Css3)</title>
<script>
function copyText()
{
document.getElementById("field2").value=document.getElementById("field1").value;
}
</script>
</head>
<body>
区域1: <input type="text" id="field1" value="Welcome to FishC"><br>
区域2: <input type="text" id="field2"><br><br>
<button onclick="copyText()">复制文本</button>
<p>当按钮被单击时触发函数。此函数把文本从 区域1 复制到 区域2 中。</p>
</body>
</html>
当按钮被单击时触发函数。此函数把文本从 区域1 复制到 区域2 中。