JS学习笔记第一天

来源:互联网 发布:无影无踪软件下载 编辑:程序博客网 时间:2024/05/22 03:19

周六加班调休,周日休息睡到日上三竿,醒来发现外面白茫茫一片。中午喝了暖胃的粥,吃点小菜,下午还是忍不住出去溜达啦。木有学习啊!晚上才回来,冻死了。北京这两天真冷啊!不过晚上还是学习了一会会。。。记录一下自己的学习笔记吧!发现学语言最好的方式就是写代码,练习!还有发现语言这个东西真是好严谨 啊!不能写错标点符号啊啊啊啊啊!

创建简单的脚本
1.在web页面里添加javascript
(1)把javascript语句直接包含在HTML文件里
<script>
...javascript语句
</script>
(2)将javascript语句单独保存在一个文件,利用<script>标签的src(源)属性把这个文件包含到页面里。
<script src='mycode.js'></script>
将javascript代码保存到单独的文件有不少的好处:
当javascript代码有更新时,这些更新可以立即作用于使用这个javascript文件的页面。这对于javascript库是尤为重要的。
HTML页面的代码可以保持简洁,从而提高易读性和可维护性。
可以稍微改善一点性能,浏览器会把包含文件进行缓存,当前页面或其他页面再次需要使用这个文件时,就可以直接从内存读取了。
程序清单1
<!DOCTYPE html>
<html>
<head>
<title>A Simple Page</title>
</head>
<body>
<P>some content</p>
<script src='mycode.js'></script>
</body>
</html>
程序清单2
<!DOCTYPE html>
<html>
<head>
<title>fahrenheit from celsius</title>
</head>
<body>
<script>
var ctemp=100;
var htemp=((ctemp*9)/5)+32;
document.write("Temperature in celsius:"+ctemp+"+degrees"</br>)
document.write("Temperature in fahrenheit:"+htemp+"+degrees")
</script>
</body>
</html>
程序清单3
<!DOCTYPE html>
<html>
<head>
<title>Onclick Demo</title>
</dead>
<body>
<input type="button" onclick="alert('you click the button')" value="Click me">
</body>
</html>
程序清单4
<!DOCTYPE html>
<html>
<head>
<title>onMouseOver Demo</title>
</head>
<body>
<image src="10013-11122119534217.jpg" alt="10013-11122119534217.jpg" onmouseover="alert('you enter the image!')">
</body>
</html>
程序清单5
<!DOCTYPE html>
<html>
<head>
<title>onMouseOver Demo</title>
</head>
<body>
<image src="10013-11122119534217.jpg" alt="10013-11122119534217.jpg" onmouseover="this.src='10013-11122119534217.jpg';" onmouseout="this.src='2531170_133325708000_2.jpg;'">
</body>
</html>


0 0
原创粉丝点击