分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

JS ??indexOf(),split(),substring(),substr(),Math.ceil(),Math.floor(),Math.round()的内容

发布时间:2023-09-06 02:05责任编辑:苏小强关键词:暂无标签

indexOf():

var mystr="Hello WorHld!"

括号内若只有一个参数,代表要查找的字符;例:document.write(mystr.indexOf("H"));

括号内若有两个参数,前一个代表要查找的字符,后一个代表从哪个位置开始查找;例:document.write(mystr.indexOf("H",7));

若要查找的字符没有,则返回-1

split():切割符

var mystr="86-010-85468578";

括号内若填 "-" ,则表示在"-"切割,结果为:86,010,85468578

括号内若填 "-" ,2 ,则表示在"-"切割,切两段,结果为:86,010

括号内若填 "" ,则每个字符都会被分割,结果为:8,6,-,0,1,0,-,8,5,4,6,8,5,7,8

括号内若填 "",3 ,则前三个字符都会被分割,结果为:8,6,-

substring():提取字符串

var mystr="Hello World!"

当substring()的括号内填 一个(数字)参数 a,则表示返回从a(包括a)开始一直到  结尾.length-1  的字符

当substring()的括号内填 两个(数字)参数  a,b ,则表示返回从a(包括a)开始一直到b的字符

substr():提取指定数目

var mystr="Hello World!";

当括号内填一个(数字)参数a时,表示从a(不包括a)开始一直到  结尾

当括号内填两个(数字)参数 a,b 时,表示从a开始,到后面的 b 个字符,例:document.write(mystr.substr(0,5));——输出:Hello

var mystr="Hello World!";

-1是倒数第一个字符(!),-2是倒数第二个字符(d!),依此类推

Math.ceil():向上取整数

例:document.write(Math.ceil(-9.9));——输出:-9

document.write(Math.ceil(-0.1));——输出:0

Math.floor():想下取整

例:document.write(Math.floor(-9.9));——输出:-10

document.write(Math.floor(-0.1));——输出:-1

Math.round():四舍五入

例:document.write(Math.round(-9.9));——输出:-10

document.write(Math.round(-0.1));——输出:0

JS ??indexOf(),split(),substring(),substr(),Math.ceil(),Math.floor(),Math.round()的内容

原文地址:https://www.cnblogs.com/chenyuan7/p/9164946.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved