码迷,mamicode.com
首页 > 编程语言 > 详细

javascript

时间:2017-07-28 12:14:27      阅读:166      评论:0      收藏:0      [点我收藏+]

标签: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的用法.

function myFunction() {
document.getElementById("demo").innerHTML="我的第一个 JavaScript 函数";
}
 
 

<!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>

--
 
 
 
链接:https://www.nowcoder.com/questionTerminal/2c5d8105b2694d85b06eff85e871cf50
来源:牛客网

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>
...changes the paragraph from saying "hi there" to saying "Updated by code"

javascript

标签:bar   dom   www   com   doc   显示   保存   mit   this   

原文地址:http://www.cnblogs.com/wanghui626/p/7249515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!