<body>
<h2 id="con">I love JavaScript</H2>
<p> JavaScript使网页显示动态效果并实现与用户交互功能。</p>
<script type="text/javascript">
function got(x){
document.getElementById(x);
}
got(con).style.color="red";
// document.getElementById("con").style.color="red"
</script>
</body>
got("con")
加个Return 是什么意思
参考代码
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>style样式</title> </head> <body> <h2 id="con">I love JavaScript</H2> <p> JavaScript使网页显示动态效果并实现与用户交互功能。</p> <script type="text/javascript"> function got(x){ return document.getElementById(x); } got('con').style.color="red"; </script> </body> </html>