1个回答
展开全部
getElementById() 方法可返回对拥有指定 ID 的第一个对象的引用。
<html>
<head>
<script type="text/javascript">
function getValue()
{
var x=document.getElementById("myHeader");
var mylabel = document.getElementById("mylabel");
mylabel.innerHTML(x.innerHTML);
}
</script>
</head>
<body>
<h1 id="myHeader" onclick="getValue()">This is a header</h1>
<p>Click on the header to alert its value</p>
<label id = "mylabel"></label>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function getValue()
{
var x=document.getElementById("myHeader");
var mylabel = document.getElementById("mylabel");
mylabel.innerHTML(x.innerHTML);
}
</script>
</head>
<body>
<h1 id="myHeader" onclick="getValue()">This is a header</h1>
<p>Click on the header to alert its value</p>
<label id = "mylabel"></label>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询