2018-08-18-Python全栈开发day41-js基础dom
1.js的作用域
和python类似
2.window对象
bom是属于浏览器模型。。所有的浏览器都支持window对象
2.1window.alert
2.2 window.confirm
ret=window.confirm(111),除了弹出窗口之外,还显示确定和取消,有选择之后,会得到相应的返回值TRUE和false
2.3 window.prompt
ret=window.prompt(111),如果输入文本并且确定,返回值为输入的值,点击取消返回null
2.4 open(url)
window.open('www.baidu.com');打开一个新的页面
3.setInterval(),clearinterval
按照指定的周期来调用函数或者表达式
setInterval(f,1000); function f() { alert(111) } 每过1000毫秒也就是1秒调用一次f函数
<input type="text" id="input1" onclick="begin()">
<button id="button1" onclick="end()">结束</button>
<script>
function showtime() {
var time= new Date().toLocaleString();
// cuurent_data=time.toLocaleString();
var ele=document.getElementById("input1");
ele.value=time
}
var clock;
function begin() {
if (clock==undefined){
showtime();
clock=setInterval(showtime,1000)
}
}
function end() {
clearInterval(clock);
clock=undefined
4.history对象和location对象
<button onclick="history.back()">hello</button>返回到刚才过来的那个页面 history.forward是跳回去
history.go(-1)、、、、history.go(1)
和back和forward对应,是返回和前进
4.2 location
lcoation.assign('127.0.0.1')直接跳转到某个连接
location.reload()-刷新
location.replace(‘127.0.0.1’),用这个连接替换当前网页,但是不能back

浙公网安备 33010602011771号