js 定时器操作 数据对象操作

原文链接: http://www.cnblogs.com/gyh04541/p/7339073.html
    <script>

var id;
function start() {
if(id=undefined){
foo()
id=setInterval(foo,1000);
}
}

function foo() {
var timer=new Date().toString();
var ele=document.getElementById('time');
ele.value=timer;
}

function end() {
clearInterval(id);
id=undefined;
}
</script>

</head>
<body>

<input type="text" id="time">
<button onclick="start()"> start</button>
<button onclick="end()">end</button>




// var arrname=[11,2,33];
// console.log(arrname);
var arrname=new Array('a','v','b');//创建数组对象
console.log(arrname);//(3) ["a", "v", "b"]
console.log(typeof arrname)//返回object类型

console.log(typeof a)//返回string类型
//
// var dd=new Array('周一','周二');//创建数组对象
// console.log(dd)//(3) ["a", "v", "b"]
//
// var cc=new Date();//创建时间对象
// console.log(cc)//Tue Aug 08 2017 14:09:03 GMT+0800 (中国标准时间)
//
// var bb=new String('hello world')//创建字符串对象
// console.log(bb)

// var aa=new Number.MAX_VALUE;//利用数字对象获取可表示的最大数
// console.log(aa)

var a='Hello ';
console.log(a.length)//5 获取字符从的长度
console.log(typeof a);
console.log(a.toLowerCase()) ;//hello 把字符串转为小写
console.log(a.toUpperCase());//HELLO 转为大写
// alert(a.trim())
console.log(a.trim())//Hello去掉字符串两边的空格,也可以去掉两边换行符

//字符串查询方法
//根据索引查字符
console.log(a.charAt(4))//填写索引值,获取字符
console.log(a.indexOf('o',1))//2个意思,1当一个参数时,根据字符,找索引值
// 2.2个参数时第一个值是要找的字符串,第二个是
//从指定的索引值开始找,找到就返回索引值,
//找不到就-1,从左向右找

var a1='hellopipp'
console.log(a1.lastIndexOf('p'))//在字符串a1里查找字符p,
//如果有多个相同的字符,就返回最后一个字符的索引,
//没有匹配,就返回-1; 从右向左找

var a2='hello world gu!'
console.log(a2.match('world'))//["world", index: 7, input: "hello world!"]
console.log(a2.search('world'))//6 返回匹配到第一个字符的索引值

//截断字符串,取字符串一部分
console.log(a2.substr(2,4));//llo索引4的位置也取值
console.log(a2.substring(2,4));//ll 索引4的位置不取,顾头不顾尾
console.log(a2.replace('ll','f'))//hefo world gu!
//替换,旧的再前,新的在后
console.log(a2.concat('rr'))//hello world gu!rr,字符串拼接
console.log(a2.split(' '))//(3) ["hello", "world", "gu!"],按照空格分割,得到数组
console.log(a2.split(' ')[1])//world,按照索引取值
</script>
//        var arrname=[11,2,33];
// console.log(arrname);
var arrname=new Array('a','v','b');//创建数组对象
console.log(arrname);//(3) ["a", "v", "b"]
console.log(typeof arrname)//返回object类型

console.log(typeof a)//返回string类型
//
// var dd=new Array('周一','周二');//创建数组对象
// console.log(dd)//(3) ["a", "v", "b"]
//
// var cc=new Date();//创建时间对象
// console.log(cc)//Tue Aug 08 2017 14:09:03 GMT+0800 (中国标准时间)
//
// var bb=new String('hello world')//创建字符串对象
// console.log(bb)

// var aa=new Number.MAX_VALUE;//利用数字对象获取可表示的最大数
// console.log(aa)

var a='Hello ';

console.log(a.length)//5 获取字符从的长度
console.log(typeof a);

console.log(a.toLowerCase()) ;//hello 把字符串转为小写
console.log(a.toUpperCase());//HELLO 转为大写
// alert(a.trim())
console.log(a.trim())//Hello去掉字符串两边的空格,也可以去掉两边换行符

//字符串查询方法
//根据索引查字符
console.log(a.charAt(4))//填写索引值,获取字符
console.log(a.indexOf('o',1))//2个意思,1当一个参数时,根据字符,找索引值
// 2.2个参数时第一个值是要找的字符串,第二个是
//从指定的索引值开始找,找到就返回索引值,
//找不到就-1,从左向右找

var a1='hellopipp'
console.log(a1.lastIndexOf('p'))//在字符串a1里查找字符p,
//如果有多个相同的字符,就返回最后一个字符的索引,
//没有匹配,就返回-1; 从右向左找

var a2='hello world gu!'
console.log(a2.match('world'))//["world", index: 7, input: "hello world!"]
console.log(a2.search('world'))//6 返回匹配到第一个字符的索引值

//截断字符串,取字符串一部分
console.log(a2.substr(2,4));//llo索引4的位置也取值
console.log(a2.substring(2,4));//ll 索引4的位置不取,顾头不顾尾
console.log(a2.replace('ll','f'))//hefo world gu!
//替换,旧的再前,新的在后
console.log(a2.concat('rr'))//hello world gu!rr,字符串拼接
console.log(a2.split(' '))//(3) ["hello", "world", "gu!"],按照空格分割,得到数组
console.log(a2.split(' ')[1])//world,按照索引取值
</script>

转载于:https://www.cnblogs.com/gyh04541/p/7339073.html

猜你喜欢

转载自blog.csdn.net/weixin_30294709/article/details/94795607