js的对话框:
1.警告框(alert)--出现一个提示信息
2.询问框(prompt)--返回输入的值
<script>
var username = prompt("请输入你的名字");
document.write("你好"+username);
</script>
3.确认框(confirm)--根据不同的选择,返回true/false
js内置对象
1.this--指当前对象//即当前标签对象
2.for...in--in后跟一个对象,对此对象中的所有元素循环一次
<script>
var a = new Array('qq','ww','ee','rr');
for(eee in a){
document.write(eee+"--");//eee为下标,但其实是对象的属性名,即0,1,2,3
document.write(a[eee]+"<br>");//a[eee]才是真正的值,与增强for循环不同
}
</script>
3.with--为一段代码建立一个缺省的对象,任何无对象的属性引用都将使用该缺省的对象
<script>
with(document){
write("1");
write("2");
write("3");
write("4");
}
</script>
4.new--生成新的对象
窗口中的对象和元素
1.window
(1)当前窗口
<script>
window.status="hello,Please look here"
</script>
(2)新开窗口//目前很少使用
window.open("1.htm","newWin","toolbar=no,left=200,top=100,menubar=no,width=100,height=100,resizable=no")
//newWin是窗口名称,resizable是不可改变大小
(3)通过本地窗口控制新开窗口
var abc = window.open("1.htm","newWin");
<input type="button" οnclick="abc.close();" value="关闭"/>
2.location
获取或设置现有文档的URL
window.location()和document.location()是一样的
3.history
先前访问过的URL的历史列表
常用方法:back();go(number);
<script>
function go2(){
window.location="33.htm";//history.back();
}
</script>
<input type="button" value="转向" οnclick="go2();"/>
4.document
当前的文档对象
document.write() 向客户端浏览器输出内容
document.formName 可以用这个方法得到表单名称
document.referrer 取得上一页面的url
04js基础 内置对象 DOM与BOM
最新推荐文章于 2022-01-12 11:35:00 发布