美文网首页
JavaScript function 对象(对象属性)

JavaScript function 对象(对象属性)

作者: 小杰的简书 | 来源:发表于2018-06-25 09:46 被阅读0次

decodeURI()

decodeURI()方法返回指定位置的字符串

<script type="text/javascript">

var test1="http://www.w3school.com.cn/My first/"

document.write(encodeURI(test1)+ "<br />")
document.write(decodeURI(test1))

</script>
输出:

http://www.w3school.com.cn/My%20first/
http://www.w3school.com.cn/My first/

decodeURIComponent()

decodeURIComponent()函数可对 encodeURIComponent() 函数编码的 URI 进行解码。

<script type="text/javascript">

var test1="http://www.w3school.com.cn/My first/"

document.write(encodeURIComponent(test1)+ "<br />")
document.write(decodeURIComponent(test1))

</script>
输出:

http%3A%2F%2Fwww.w3school.com.cn%2FMy%20first%2F
http://www.w3school.com.cn/My first/

encodeURI()

encodeURI()函数可把字符串作为 URI 进行编码。

<script type="text/javascript">

document.write(encodeURI("http://www.w3school.com.cn")+ "<br />")
document.write(encodeURI("http://www.w3school.com.cn/My first/"))
document.write(encodeURI(",/?:@&=+$#"))

</script>
输出:

http://www.w3school.com.cn
http://www.w3school.com.cn/My%20first/
,/?:@&=+$#

encodeURIComponent()

encodeURIComponent()函数可把字符串作为 URI 组件进行编码。

<script type="text/javascript">

document.write(encodeURIComponent("http://www.w3school.com.cn"))
document.write("<br />")
document.write(encodeURIComponent("http://www.w3school.com.cn/p 1/"))
document.write("<br />")
document.write(encodeURIComponent(",/?:@&=+$#"))

</script>
输出:

http%3A%2F%2Fwww.w3school.com.cn
http%3A%2F%2Fwww.w3school.com.cn%2Fp%201%2F
%2C%2F%3F%3A%40%26%3D%2B%24%23

escape()

escape()函数可把字符串作为 URI 组件进行编码。

<script type="text/javascript">

document.write(escape("Visit W3School!") + "<br />")
document.write(escape("?!=()#%&"))

</script>
输出:

Visit%20W3School%21
%3F%21%3D%28%29%23%25%26

eval()

eval()函数可计算某个字符串,并执行其中的的 JavaScript 代码。

<script type="text/javascript">

eval("x=10;y=20;document.write(x*y)")

document.write(eval("2+2"))

var x=10
document.write(eval(x+17))

</script>
输出:

200
4
27

isNaN()

isNaN()函数用于检查其参数是否是非数字值。

<script>

document.write(isNaN(123));
document.write(isNaN(-1.23));
document.write(isNaN(5-2));
document.write(isNaN(0));
document.write(isNaN("Hello"));
document.write(isNaN("2005/12/12"));

</script>
输出:

false
false
false
false
true
true

Number()

Number()函数把对象的值转换为数字。

<script type="text/javascript">

var test1= new Boolean(true);
var test2= new Boolean(false);
var test3= new Date();
var test4= new String("999");
var test5= new String("999 888");

document.write(Number(test1)+ "<br />");
document.write(Number(test2)+ "<br />");
document.write(Number(test3)+ "<br />");
document.write(Number(test4)+ "<br />");
document.write(Number(test5)+ "<br />");

</script>
输出:

1
0
1256657776588
999
NaN

parseFloat()

parseFloat()数可解析一个字符串,并返回一个浮点数。

<script type="text/javascript">

document.write(parseFloat("10")) 
document.write(parseFloat("10.00")) 
document.write(parseFloat("10.33")) 
document.write(parseFloat("34 45 66")) 
document.write(parseFloat(" 60 ")) 
document.write(parseFloat("40 years"))
document.write(parseFloat("He was 40"))

</script>
输出:

10
10
10.33
34
60
40
NaN

parseInt()

parseInt()函数可解析一个字符串,并返回一个整数。

parseInt("10");         //返回 10
parseInt("19",10);      //返回 19 (10+9)
parseInt("11",2);       //返回 3 (2+1)
parseInt("17",8);       //返回 15 (8+7)
parseInt("1f",16);      //返回 31 (16+15)
parseInt("010");        //未定:返回 10 或 8

相关文章

  • JavaScript function 对象(对象属性)

    decodeURI() decodeURI()方法返回指定位置的字符串 decodeURIComponent() ...

  • 《javascript启示录》笔记(上)

    1. javascript对象 a. 在javascript中,方法是包含Function()对象的属性,其目的是...

  • 函数原型链结构图(未完)

    Function是对象也是函数,因此Function拥有了函数的属性prototype,还有对象的属性__prot...

  • 对象_原型

    理解对象 对象 定义有属性property和方法function就是对象。解析属性property:描述对象的状态...

  • 05.Object函数

    JavaScript函数是引用类型(对象类型),所以Function函数也是对象 2."Function构造函数"...

  • js的prototype

    javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解...

  • JavaScript - prototype理解

    Javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解...

  • JavaScript对象属性

    JavaScript对象属性 简单理解对象 运行环境 node V10.16.3 对象属性 数据属性数据属性包含...

  • js原型与原型链

    一. 普通对象与函数对象 JavaScript 中,分为普通对象和函数对象,Object ,Function 是J...

  • 2018-05-18 原型链

    1:普通对象与函数对象 JavaScript分为普通对象和函数对象,通过new Function创建的对象都是函数...

网友评论

      本文标题:JavaScript function 对象(对象属性)

      本文链接:https://www.haomeiwen.com/subject/avgcyftx.html