JavaScript
2013-11-07 09:07
525 查看
<script>标签中不在需要type="text/javascript" <script src="myScript.js"></script>
JavaScript is the default scripting language in HTML5 and in all modern browsers!
"Everything" in JavaScript is an Object.
var x=document.getElementById("demo").value;
if(x=="") throw "empty";
if(isNaN(x)) throw "not a number";
if(x>10) throw "too high";
if(x<5) throw "too low";
} catch(err) {
y.innerHTML="Error: " + err + ".";
}
exec() method searches a string for a specified value, and returns the text of the found value. If no match is found, it returns null.
Finding HTML elements by tag name
Finding HTML elements by class name(does not work in Internet Explorer 5,6,7, and 8)
Finding HTML elements by HTML object collections(document.forms["frm1"], anchors,images,links)]
changing html content: document.getElementById(id).innerHTML=new HTML
changing the value of attribute: document.getElementById(id).attribute=new value
var h=window.innerHeight|| document.documentElement.clientHeight|| document.body.clientHeight;
window.open() - open a new window
window.close() - close the current window
window.moveTo() -move the current window
window.resizeTo() -resize the current window
location.pathname returns the path and filename of the current page
location.port returns the port of the web host (80 or 443)
location.protocol returns the web protocol used (http:// or https://)
location.href returns the the URL of the current page.
location.assign() method loads a new document.
history.forward() - same as clicking forward in the browser
Since different browsers support different objects, you can use objects to detect browsers.
if (window.opera) {...some action...}
confirm("sometext");
prompt("sometext","defaultvalue");
setTimeout("function",milliseconds) - executes a function, once, after waiting a specified number of milliseconds
clearInterval(intervalVariable) - stop the execution
getCookie("username"); setCookie("username",username,365);
Array object
Boolean object
Date object
Math object
Number object
String object
RegExp object
Global properties and functions
Window object
Navigator object
Screen object
History object
Location object
HTML Document
HTML Element
HTML Attributes
HTML Events
Anchor object
Area object
Base object
Body object
Button object
Form object
Frame/IFrame object
Frameset object
Image object
Input Button object
Input Checkbox object
Input File object
Input Hidden object
Input Password object
Input Radio object
Input Reset object
Input Submit object
Input Text object
Link object
Meta object
Object object
Option object
Select object
Style object
Table object
td / th object
tr object
Textarea object
JavaScript is the default scripting language in HTML5 and in all modern browsers!
JavaScript Data Types
String, Number, Boolean, Array, Object, Null, Undefined"Everything" in JavaScript is an Object.
JavaScript Errors - Throw and Try to Catch
try {var x=document.getElementById("demo").value;
if(x=="") throw "empty";
if(isNaN(x)) throw "not a number";
if(x>10) throw "too high";
if(x<5) throw "too low";
} catch(err) {
y.innerHTML="Error: " + err + ".";
}
Boolean Object
0, -0, null, "", false, undefined, NaN --- falseRegExp Object
test() method searches a string for a specified value, and returns true or false, depending on the result.exec() method searches a string for a specified value, and returns the text of the found value. If no match is found, it returns null.
JavaScript HTML DOM
Finding HTML Elements
Finding HTML elements by idFinding HTML elements by tag name
Finding HTML elements by class name(does not work in Internet Explorer 5,6,7, and 8)
Finding HTML elements by HTML object collections(document.forms["frm1"], anchors,images,links)]
Changing the HTML
changing the output stream: document.write(Date());changing html content: document.getElementById(id).innerHTML=new HTML
changing the value of attribute: document.getElementById(id).attribute=new value
Changing HTML Style
document.getElementById(id).style.property=new styleThe Browser Object Model
The Window Object
var w=window.innerWidth|| document.documentElement.clientWidth|| document.body.clientWidth;var h=window.innerHeight|| document.documentElement.clientHeight|| document.body.clientHeight;
window.open() - open a new window
window.close() - close the current window
window.moveTo() -move the current window
window.resizeTo() -resize the current window
Window Screen
Window Location
location.hostname returns the domain name of the web hostlocation.pathname returns the path and filename of the current page
location.port returns the port of the web host (80 or 443)
location.protocol returns the web protocol used (http:// or https://)
location.href returns the the URL of the current page.
location.assign() method loads a new document.
Window History
history.back() - same as clicking back in the browserhistory.forward() - same as clicking forward in the browser
Window Navigator
The information from the navigator object can often be misleading, and should not be used to detect browser version.Since different browsers support different objects, you can use objects to detect browsers.
if (window.opera) {...some action...}
Popup Box
alert("sometext");confirm("sometext");
prompt("sometext","defaultvalue");
JavaScript Timing Events
setInterval("function",milliseconds) - executes a function, over and over again, at specified time intervalssetTimeout("function",milliseconds) - executes a function, once, after waiting a specified number of milliseconds
clearInterval(intervalVariable) - stop the execution
JavaScript Cookie
A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With JavaScript, you can both create and retrieve cookie values.getCookie("username"); setCookie("username",username,365);
JavaScript Objects Reference
The references describe the properties and methods of each object, along with examples.Array object
Boolean object
Date object
Math object
Number object
String object
RegExp object
Global properties and functions
Browser Objects Reference
The references describe the properties and methods of each object, along with examples.Window object
Navigator object
Screen object
History object
Location object
HTML DOM Reference
The references describe the properties and methods of the HTML DOM, along with examples.HTML Document
HTML Element
HTML Attributes
HTML Events
HTML Element Objects Reference
The references describe the properties and methods of each HTML object, along with examples.Anchor object
Area object
Base object
Body object
Button object
Form object
Frame/IFrame object
Frameset object
Image object
Input Button object
Input Checkbox object
Input File object
Input Hidden object
Input Password object
Input Radio object
Input Reset object
Input Submit object
Input Text object
Link object
Meta object
Object object
Option object
Select object
Style object
Table object
td / th object
tr object
Textarea object
相关文章推荐
- javascript 注入实现跨html跨浏览器传参
- js获取页面宽度高度及屏幕分辨率
- javascript数据类型
- JavaScript判断浏览器类型及版本
- 'use strict' JavaScript严格模式
- ☀【JS组织】pageA_init, pageB_init
- 如何判断Javascript对象是否存在
- 判断js中各种数据的类型方法之typeof与0bject.prototype.toString讲解
- 使用javascript实现ListBox左右全选,单选,多选,全请
- javascript获取所有同类checkbox选项(实例代码)
- ztree 后台拼接Json
- js字符串转成JSON
- Javascript操作URL函数修改版
- javascript去掉前后空格的实例
- 得到form下的所有的input的js代码
- JS实现定时页面弹出类似QQ新闻的提示框
- js实现幻灯片播放图片示例代码
- js操作label给label赋值及取label的值示例
- iframe子父页面调用js函数示例
- IntelliJ、ReSharper 6折 加入慧都“惊喜惠“