标签:bar dom www com doc 显示 保存 mit this
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script>
function displayDate(){
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>
<h1>我的第一个 JavaScript 程序</h1>
<p id="demo">这是一个段落</p>
<button type="button" onclick="displayDate()">显示日期</button>
</body>
</html>
--
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<script>
function changeImage()
{
element=document.getElementById(‘myimage‘)
if (element.src.match("1.png"))
{
element.src="C:/Users/Administrator/Desktop/2.jpg";
}
else
{
element.src="C:/Users/Administrator/Desktop/1.png";
}
}
</script>
<img id="myimage" onclick="changeImage()"
src="C:/Users/Administrator/Desktop/1.png" width="100" height="180" >
<p>match function used to match where covers the word"1.png",then do the dispatch.</p>
</body>
</html>
--
myScript.js 文件代码如下:
注意这个不是嵌套在<script>标签中,如同css的用法.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<h1>我的 Web 页面</h1>
<p id="demo">一个段落。</p>
<button type="button" onclick="myFunction()">点击这里</button>
<p><b>注释:</b>myFunction 保存在名为 "myScript.js" 的外部文件中。</p>
<script src="myScript.js"></script>
</body>
</html>
document.write can be used to emit markup during the parsing of the page. It cannot be used for modifying the page after it‘s parsed. The output of document.write goes straight into the parser as though it had been in the HTML document in the first place. So for instance:
1
|
<body> <script> document.write( "<p>" ); </script> hi there</p> |
looks exactly the same to the browser as
1
|
<body> <p>hi there</p> |
innerHTML, which is not a function but rather a property, exists on all DOM element instances, and can be used to set their content, using markup. This, along with the various DOM methods available on instances, is the primary way that dynamic web pages are done. For example:
1
|
<body> <p id= "target" >Hi there</p> <script> document.getElementById( "target" ).innerHTML = "Updated by <strong>code</strong>" ; </script> </body> |
标签:bar dom www com doc 显示 保存 mit this
原文地址:http://www.cnblogs.com/wanghui626/p/7249515.html