更详细转:http://www.w3school.com.cn/jsref/jsref_obj_string.asp
//-------------------------------------------------------- // string对象属性: // length var x = [1,2,3,4,5,6] document.write(x.length) //6 //-------------------------------------------------------- // 方法: //string - anchor()方法(创建HTML锚标签) var x = "hello world!"; document.write(x.anchor("myanchor")) //<a name="myanchor">Hello world!</a> //斜体 document.write(x.italics()) //粗体 document.write(x.bold()) //查询索引 document.write(x.indexOf(‘l‘)) document.write(x.lastIndexOf(‘l‘)) 2 9 //索引截取字符串 document.write(x.substr(1,2)); //le document.write(x.substring(1,2)); // e //切片 document.write(x.slice(1,2)); document.write(x.slice(-2,-1)); //e //d
// //数组 // -join // -concat // -reverse // -sort // // -slice(1,2,3) // 位置1,索引位置 // 位置2,需要删除的个数 // 位置3,插入数据 //进出栈(先入后出) // push 、 pop //(先入先出) //shift、unshift
<script>
//创建函数
function f(x) {
console.log("this is " + x)
}
f(‘alex‘)
//传入多个参数: argument == kwargs
function f() {
var sun = 0;
for(var i =0;i<arguments.length;i++){
sun += arguments[i];
}
return sun
}
console.log(f(1,2,3,4,56,7,8,9,0))
// 匿名函数
(function(name) {
alert(name)
})(‘alex‘)
</script>
windwos对象 方法 //提示框 window.alert("OK") //确认框,返回true false var re = window.confirm(‘this confirm‘); console.log(re) //true //弹出输入框,返回输入值或者None var re2 = window.prompt("this promt") console.log(re2) //打开新的页面 open("http://www.baidu.com") close() //多长时间执行函数,1000 = 1s var f1 = setInterval(f1,3000); //取消以上操作 function s2() { clearInterval(f1) }
原文:https://www.cnblogs.com/Anec/p/9828610.html