javascript能干什么返回列表
上传时间:2015-02-02 内容关键字:
二、location对象 包括有当前url的相关信息
1. 属性:
href 设置或返回完整的url :
alert(location.href); //返回本文件所有的路径
location.href='http://www.baidu.com'; //跳转到百度
search 返回rul?后面的查询部分 :
alert(location.search); // 如果index.html?id=12 ,则输出?id=12
2.方法:
assign() 加载新的文档
location.assign('http://www.baidu.com'); //跳转到baidu
reload(boolean) 重新加载文档 和 go(0) 一个效果。如果参数是true,任何时候都会重新加载,false的 时候,只有在文档改变的时候才会加载,否则直接读取内存当中的。
location.reload(); //页面不断刷新
replace()用新的文档代替当前的文档(没有历史记录)
location.replace('http://www.baidu.com'); //跳转到baidu,且没有历史记录。
三、screen对象:
记录了客户端显示屏的信息。
1.属性:
availHeight 返回显示屏幕的高度(除Windows 任务栏之外)
availWidth 返回显示屏幕的宽度
height 返回显示屏幕的高度
width 返回显示屏幕的宽度
document.write(screen.availHeight);
document.write('
');
document.write(screen.height);
document.write('
');
document.write(screen.availWidth);
document.write('
');
document.write(screen.width);
javascript- 对表单的操作实例讲解:
一、获得表单引用:
1> 通过直接定位的方法来获取:
document.getElementById();
document.getElementsByName();
document.getELementsByTagName();
window.onload=function(){
var form1 = document.getElementById('form1');
var form1 = document.getElementsByName('form1')[0]; //即使只有一个元素也是个数组
var form1 = document.getElementsByTagName('form')[0];
alert(form1.name);
}
2> 通过集合的方式来获取引用:
document.forms[下标]
document.forms[‘name’]
document.forms.name
A. document.forms.length 查看一共有多少个form表单。
B. 实例:三种获得form对象方法
var forms = document.forms;
alert(forms[0].name); //打印form的name属性
alert(forms['form1'].name); //打印form的name属性
alert(forms.form1.action); //打印form的aciton属性
method="post" enctype="multipart/form-data">
3>通过name直接获取(只适用于表单)
document.name
window.onload=function(){
var forms = document.form1; 直接通过form表单的name=”form1”name值来获取
alert(forms.action);
}
二、获得表单元素的引用:
1> 通过直接定位的方法来获取:
document.getElementById();
document.getElementsByName();
document.getELementsByTagName();
2> 通过集合来获取:
表单对象.elements 获得表单里的所有元素的集合。
var form1 = document.form1;
alert(form1.elements.length); //获得所有元素集合的总个数
表单对象.elements.[]
表单对象.elements[‘name’]
表单对象.elements.name
window.onload=function(){
var form1 = document.form1;
var input1 = form1.elements[0].value;
var input1 = form1.elements['username'].value;
var input1 = form1.elements.username.value;
alert(input1);
}
- 上一篇:已经没有了
- 下一篇:javascript兼容性总汇