<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript基础应用</title>
</head>
<body>
<h3>javascript的使用方法</h3>
<hr/>
<script type="text/javascript">
alert("第一种使用方法");
</script>
<a href="javascript:alert(new Date())">第二种使用方法查看时间</a>
<input type="button" value="第三种使用方法点击" onclick="alert(new Date())">
</body>
</html>
![213756_g0Qr_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/bbbf526221026d05c0b9986b7ea986c7.png)
![213757_Y9gp_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/357c2287c971c12620aea949e8e3fed1.png)
![213757_0b3f_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/d4c1db4bb9127288e5128a359227783d.png)
![213757_ZYyc_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/c681a6b24c5ccd499ce290ac2b33c722.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript基础应用</title>
<script src="javascri2/js1.js" language="javascript" type="text/javascript" charset=“gbk”>
</script>
</head>
<body>
<script type="text/javascript">
</script>
</body>
</html>
js1.js
// JavaScript Document
alert("第四种使用方法");
![214238_cgeo_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/cd04148f7b29dc141d8e3277ac2574fd.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>变量的使用</title>
</head>
<body>
<script type="text/javascript">
var inum=100;
var sName="张三";
var fnum=10.0;
alert(inum);
alert(typeof sName);
alert(fnum.toString());
alert(parseInt("123a"));
alert(Boolean(0));
alert(1+1);
</script>
</body>
</html>
![214626_G9Qr_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/d81f553cb0770ea85d5664e3ba3af9c1.png)
![214626_fd0m_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/9c687043255255477910b0e1c3e0dabd.png)
![214627_UNaI_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/c180a1ae9b7b7058e37068c37cf587c8.png)
![214628_EULp_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/810e48498987ee3b0121bc4c9e2e64a9.png)
![214628_FyLv_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/6878f0923db65651acbded81deffb54b.png)
![214629_t9VC_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/31e58b85aeed96b921313450b8add719.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>控制语句</title>
</head>
<body>
<script type="text/javascript">
var inum1=2;
var inum2=3;
if(inum1>inum2){
alert("inum1>inum2");
}else{
alert("inum1<inum2");
}
var inum=9;
switch(inum){
case 1:
alert(1);
case 3:
alert(3);
case 5:
alert(5);
case 7:
alert(7);
case 9:
alert(9);
case 10:
alert(10);
default:
alert(11);break;
}
</script>
</body>
</html>
![214916_Fr5y_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/e41e0ac31624babb8a65ffacb9455d57.png)
![214916_zplP_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/7399a9da81d62bf5839367392d36ffc7.png)
![214916_TkpJ_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/b5a2220c01f87383fa3ba420ee729289.png)
![214916_9hE6_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/d22e6b73bb35bfa23efb34b816372b4d.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数</title>
</head>
<body>
<script type="text/javascript">
var s=test2(3,4);
alert(s);
function test1(){
return "没有参数";
}
function test2(a,b){
return a+b;
}
function test3(a,b){
return a-b;
}
function test4(){
for(var i=0;i<arguments.length;i++){
alert(arguments[i]);
}
}
test4(10,20,30);
</script>
</body>
</html>
![215140_fAyI_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/5c57b356f9aa74d022ef677767f758e5.png)
![215140_Kgwg_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/c592e5d5eebcaa3ace09b90de9eacb65.png)
![215142_dh4F_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/9f899a9742164cea2d8ed8cbfb1b808c.png)
![215142_bi3x_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/b557bf62b26f87201ca9012ac0f6e434.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script>
var a="This is a string";
alert(a.length);
alert(a.charAt(2));
alert(a.indexOf(2));
alert(a.lastIndexOf(2));
</script>
</body>
</html>
![215418_xWdQ_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/cd8aa1f6f7ebd4a7b5d88e618fd64ff5.png)
![215418_TPBI_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/1dcf5e1241033b90121642a32e3d42e4.png)
![215419_QRBZ_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/75def011e89e372def60656e7217e961.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>日期类</title>
</head>
<body>
<script language="javascript">
var currTime=new Date();
var str=currTime.getYear()+"年";
alert(str);
alert(currTime.toLocaleString());
var uri1="http://www.tjitcast.com/index.html?country=中国&name=zs";
alert(encodeURI(uri1));
var uri2="http://www.tjitcast.com/index.html?country=%E4%B8%AD%E5%9B%BD&name=zs";
alert(decodeURI(uri1));
var uri3="http://www.tjitcast.com/index.html?country=中国&name=zs";
alert(encodeURIComponent(uri3));
alert(parseInt("avd",16));
alert(parseFloat("abc"));
alert(isNaN(parseFloat("abc")));
</script>
</body>
</html>
![215903_UiYu_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/5db8a3392e8021ecbb7cabdf6a9e3f6e.png)
![215903_NG4D_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/0e4203eb63371ea4c97f304d67c7f136.png)
![215903_zTRU_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/9b9fc8654fbd339fc18fa8bcb25bbe9a.png)
![215903_bfxg_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/5d81e1fd369091ac0a454ed53bce9ab9.png)
![215904_qTvT_2356966.png](http://static.oschina.net/uploads/space/2015/0430/215904_qTvT_2356966.png)
![215904_tjhr_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/808241252c641c5f90194bdc9946ad67.png)
![215904_Mlkp_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/624231e59fd20a415b101f31368be7ef.png)
![215904_5yQY_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/fa73abba272473c3c444e13837ec221f.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>创建自己的类和对象 </title>
</head>
<body>
<script>
function Animal(){
}
var animal=new Animal;
animal.name="dog";
animal.age=2;
function xiaohou(){
alert(animal.name+"--->"+animal["age"]);
}
animal.say=xiaohou;
animal.say();
function Person(){
this.name="张三";
this.age=20;
this.height=176;
}
var p=new Person();
var temp,str="";
for(temp in p){
str+=p[temp]+" ";
}
alert(str);
var arr=new Array(2);
arr[0]=0;
arr[1]=1;
arr[2]=2;
arr[3]=3;
alert(arr[3]); //3
alert(arr.toString()); //0123
alert(arr.join("--")); //0-1-2-3
alert(arr.reverse()); //3210
alert(arr.sort()); //0123
alert(arr.pop()); //3
alert(arr.toString()); //012
alert(arr.push([1],[2],[3])); //6
alert(arr.shift()); //0
alert(arr.unshift([2],[3],[6])); //8
</script>
</body>
</html>
![220310_cLLH_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/177b36add0da7d50a2be8fcf9fae2cc0.png)
![220310_PVGy_2356966.png](https://i-blog.csdnimg.cn/blog_migrate/b7ff124e6d815561bc9db3b738bdbd2b.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS事件 HTML事件</title>
<style type="text/css">
.input-text{
border-right: #a1bca3 1px solid;
border-top: #a1bca3 1px solid;
border-leB: #a1bca3 1px solid;
border-boJom: #a1bca3 1px solid;
font-size: 11px; height: 20px; width: 160px;
}
function executClick(){
alert("事件按钮");
}
</style>
</head>
<body>
<input type="text" name="txt" class="input-text" onfocus="this.style.borderColor='red'" onblur="this.style.borderColor='#A1BCA3'"/>
<hr/><hr/>
<input type="button" value="点击" onclick="executClick()"/>
<img src="../btn1.png" onmouseout="this.src='../btn2.png'" onmouseover="this.src='../btn1.png'" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS事件</title>
<script type="text/javascript">
function executClick(){
alert("事件按钮");
}
</script>
</head>
<body>
<input type="button" value="点击" onclick="executClick()"/>
<input type="text" name="txt" onkeydown="alert(event.keyCode)"/>
</body>
</html>