zoukankan
html css js c++ java
javascript权威指南例子(自己写的)
javascript权威指南例子(自己边看边写的)
前面几章的
下载
<!
DOCTYPE HTML PUBLIC
"
-//W3C//DTD HTML 4.0 Transitional//EN
"
>
<
HTML
>
<
HEAD
>
<
TITLE
>
New Document
</
TITLE
>
</
HEAD
>
<
BODY
>
<!--
sample
1
-->
<
script language
=
"
javascript
"
>
document.write(
"
<h1>hello this is Factorials</h1>
"
)
for
(i
=
0
;i
<
10
;i
++
)
{
document.write(i
+
"
*
"
+
i
+
"
=
"
+
i
*
i);
document.write(
"
<br />
"
)
}
</
script
>
<!--
sample
1
一般的事件
-->
<
input type
=
"
button
"
value
=
"
click here (eventhander)
"
onclick
=
"
alert('you clicked this button!');
"
></
input
>
<!--
sample
2
函数调用 无返回值
-->
<
br
/>
<
h3
>
sample
2
函数调用 无返回值
</
h3
><
br
/>
<
script language
=
"
javascript
"
>
function function1()
{
alert(
"
good
"
);alert(
"
yes
"
);
//
语句在不同的行中可以不写分号,建议只要是语句都要写分号。
alert(
"
1
"
)
alert(
"
2
"
)
/**/
/*
注释
*/
}
</
script
>
<
br
/>
<
input type
=
"
button
"
value
=
"
function1
"
onclick
=
"
function1();
"
></
input
>
<!--
sample
3
求平方根
-->
<
br
/>
<
h3
>
sample
3
求平方根
</
h3
><
br
/>
<
script language
=
"
javascript
"
>
function countsqrt()
{
result
=
Math.sqrt(document.getElementById(
"
numsqrt
"
).value);
//
Math.sqrt 计算平方根
document.getElementById(
"
numsqrt
"
).value
=
result;
//
把计算结果赋值给文本框
alert(result);
//
alert((255).toString(0x10))
}
</
script
>
<
input type
=
"
text
"
id
=
"
numsqrt
"
value
=
"
2
"
></
input
>
<
input type
=
"
button
"
id
=
"
countsqrt
"
value
=
"
计算平方根
"
onclick
=
"
countsqrt();
"
></
input
>
<!--
sample
4
特殊数值的常量
-->
<
script language
=
"
javascript
"
>
document.write(
"
<br /> <h3>sample 4 特殊数值的常量</h3><br />
"
)
document.write(
"
Number.MAX_VALUE:
"
+
Number.MAX_VALUE
+
"
<br />
"
);
document.write(
"
Number.MIN_VALUE:
"
+
Number.MIN_VALUE
+
"
<br />
"
);
document.write(
"
Number.MIN_VALUE:
"
+
Number.MIN_VALUE
+
"
<br />
"
);
document.write(
"
Number.NaN
"
+
Number.NaN
+
"
<br />
"
);
document.write(
"
Number.POSTIVE_INFINITY
"
+
Number.POSTIVE_INFINTITY
+
"
\n\r\f1111<br />
"
);
</
script
>
<!--
sample
5
字符串常用操作
-->
<
script language
=
"
javascript
"
>
document.write(
"
<br /> <h3>sample 5 字符串常用操作</h3><br />
"
)
msg
=
"
wuyisky
"
;
document.write(msg.length);
function StringOperate()
{
var index
=
document.getElementById(
"
Operate
"
).value;
var word
=
document.getElementById(
"
stringInput
"
).value;
switch
(index)
{
case
"
getLength
"
:
alert(
"
\
""
+word+
"
\
"
的长度是:
"
+
word.length);
break
;
case
"
getLastChar
"
:
alert(
"
\
""
+word+
"
\
"
的最后一个字符是:
"
+
word.charAt(word.length
-
1
));
//
charAt:返回指定索引位置处的字符。strObj.charAt(index); strObj 是string类型,index: from 0 to strObj.length-1
alert(
"
substring(2)结果是:
"
+
word.substring(
2
)
+
"
// 从参数的索引位置开始到结尾的子字符串
"
);
alert(
"
word.substring(2,4)结果是:
"
+
word.substring(
2
,
4
)
+
"
// 从参数1的索引位置开始到参数2的索引位置结束
"
);
alert(
"
word.substr(2,4)结果是:
"
+
word.substr(
2
,
4
)
+
"
// 从参数1的索引位置开始的参数2个字符
"
);
alert(
"
word.slice(2,4)结果是:
"
+
word.slice(
2
,
4
)
+
"
// 从参数1的索引位置开始的参数2个字符
"
);
break
;
default
:
alert(word);
}
}
</
script
>
<
input type
=
"
text
"
id
=
"
stringInput
"
value
=
"
被操作的字符串
"
></
input
>
<
select id
=
"
Operate
"
onchange
=
"
StringOperate();
"
>
<
option value
=
"
getLength
"
>
求长度
</
option
>
<
option value
=
"
getLastChar
"
>
取最后一个字符
</
option
>
<
option value
=
"
2
"
>
求长度
</
option
>
<
option value
=
"
3
"
>
求长度
</
option
>
</
select
>
<!--
sample
6
函数直接量
-->
<
script language
=
"
javascript
"
>
document.write(
"
<br /> <h3>sample 6 函数直接量</h3><br />
"
)
var f
=
function(x)
{
return
x}
;
var s
=
f(
"
函数直接量;
"
)
document.write(s);
</
script
>
<!--
sample
7
对象直接量
-->
<
script language
=
"
javascript
"
>
document.write(
"
<br /> <h3>sample 7 对象直接量</h3><br />
"
)
var point
=
new
Object();
//
create a Object
point.x
=
2
;
//
属性x
point.y
=
3
;
//
属性y
document.write(point.x.toString()
+
point.y.toString());
var point1
=
{x:
2
,y:
3
}
;
//
对象直接量
document.write(point1.x.toString()
+
point1.y.toString());
</
script
>
<!--
sample
8
数组的使用
-->
<
script language
=
"
javascript
"
>
document.write(
"
<br /> <h3>sample 8 数组的使用</h3><br />
"
)
var a
=
new
Array();
a[
0
]
=
1
;
a[
1
]
=
"
wuyi
"
;
a[
2
]
=
true
;
a[
3
]
=
{x:
1
,y:
"
a string
"
}
;
for
(i
=
0
;i
<=
3
;i
++
)
{
document.write(
"
<br />
"
+
a[i]);
}
document.write(a[
3
].x
+
a[
3
].y);
</
script
>
<!--
sample
9
数组的使用
-->
<
br
/>
<
h3
>
sample
9
函数中声明的所有变量在整个函数中都有定义
</
h3
><
br
/>
</
BODY
>
</
HTML
>
查看全文
相关阅读:
CEO良言:创业就请在29岁前做富翁
在酒桌上看出她是哪种女人!
巴菲特的人生财富课
曹操的领导力:羊群变狮群(领导艺术终极体现)
商业模式木桶短板原理与长板原理
这三种力量,让你的人生从此大不一样……
都市男女的30句妙语叹息
郎咸平:诸葛亮是一名优秀的企业家吗?
做小生意,解决生活中的问题:创业路上的成功感悟
100个成功经验(价格不菲的培训课程笔记摘要)
原文地址:https://www.cnblogs.com/wuyisky/p/913395.html
最新文章
带导航控制器,页面切换及图片显示 on 0523
iphone example
ScrollView 简单例子
TableView Demo
重啟IIS iisreset
Iphone LINK
poj3903
poj3917
poj3852
poj4022
热门文章
poj3994
淡忘于江湖
因为有你
广告营销中最能赚钱的10个广告词
战胜自己、成为自己:天下最容易的事情就是……
因为我们是朋友
赖丹(帮别人名字作诗)
人际关系的第一要素
整理你的博客订阅:15个步骤收获一生的学习习惯
贫穷者的财富只有大脑:一定要掌握穷变富的哲理
Copyright © 2011-2022 走看看