HTML如何调用JavaScript函数?

<html>
<head>
<title>使用“javascript:”</title>
</head>
<body>
<p id="p1">段落</p>
</body>
</html>
我是一个javaScript初学者。以上一个html我要用JavaScript实现对<p></p>标签之间内容的控制。本想通过document.getElementById("p1").innerText来设置里面的值的,但是试了好几次没有成功,不知道怎样设置。请告示指教,回答者请给出完整的代码。
还有就是HTML如何调用javascript的函数?

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> new document </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<script language="javascript" type="text/javascript">
function getp1(){
alert(document.getElementById("p1").innerHTML);
}
</script>
</head>
<body>
<p id="p1">段落</p>
<input type="button" onclick="getp1()" value="获取P1"/>
</body>
</html>追问

这个问题我自己已经解决了,还是谢谢您!

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-27
<p id="p1">段落</p>
<script language="javascript" type="text/javascript">
document.getElementById("p1").innerText = "修改的值";
</script>
第2个回答  2012-08-27
如果在火狐,不能用innerText,要用contentText
若无特殊html语法
可用innerHTML

ex:
document.getElementById("p1").innerHTML="我被修改了"
第3个回答  2012-08-28
<p id="p1">段落</p>

<script>document.getElementById("p1").innerText="1231231"</script>
js代码要写在 后面,不然读不到你的元素的,