BOM - history与search处理
<head>
<metacharset="utf-8">
<title></title>
<script>
window.onload =function(){
var oBtn =document.getElementById("btn");
oBtn.onclick= function(){
alert(history.length)
}
}
</script>
</head>
<body>
<input type="button" value="按钮"id="btn" />
</body>
<head>
<metacharset="utf-8">
<title></title>
<script>
window.onload =function(){
var oBtn = document.getElementById("btn");
oBtn.onclick= function(){
alert(history.length)
}
var oForward = document.getElementById("forward")
oForward.onclick= function(){
history.forward();
}
var oBack = document.getElementById("back")
oBack.onclick = function(){
history.back();
}
var oGo =document.getElementById("go")
}
</script>
</head>
<body>
<input type="button" value="记录"id="btn" />
<input type="button" value="前进"id="forward" />
<input type="button" value="后退"id="back" />
<input type="button" value="go"id="go" />
</body>
var oGo = document.getElementById("go")
oGo.onclick = function(){
history.go( 0 );
}
var oGo = document.getElementById("go")
oGo.onclick = function(){
history.go( 2 );
}
var oGo = document.getElementById("go")
oGo.onclick = function(){
history.go( -2 );
}
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8">
<title></title>
</head>
<script>
function getValue(search,key){
//1.找出key第一次出现的位置
var start = search.indexOf(key);
if(start == -1){
return;
}else{
//2.说明找到了,找出键值对。结束的位置
var end = search.indexOf("&",start);
if(end == -1){
//这是最后一个键值对
end = search.length;
}
}
//3.将这个键值对提取出来
var str = search.substring(start,end);
//4.key=value 获取value
var arr = str.split("=");
return arr[1];
}
var search = "?id=5&search=ok";
alert(getValue(search,"id"));
</script>
<body>
</body>
</html>
赞 (0)