案例:html/html5 案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<script>
5
function copyText()
6
{
7
document.getElementById("field2").value=document.getElementById("field1").value;
8
}
9
</script>
10
</head>
11
<body>
12
13
Field1: <input type="text" id="field1" value="Hello World!"><br>
14
Field2: <input type="text" id="field2"><br><br>
15
16
<button onclick="copyText()">复制文本</button>
17
18
<p>当按钮被单击时触发函数。此函数把文本从 Field1 复制到 Field2 中。</p>
19
20
</body>
21
</html>
22