Changing HTML Properties
To change the attributes of an HTML element, use this syntax:
document.getElementById (ID). attribute=new valueThis example changes the SRC attribute of the element:
Change HTML Style
To change the style of HTML elements,
1): Join () Method:Converts all elements of an array into strings.Like what:
var a = [1,2,3];var s = a.join (); Output s==1,2,3Of course, you can also specify a separator;Like
\s = A.join (",");In contrast to String.Split (), split () splits a
The arguments object is not an array and accesses a single argument in the same way that it accesses an array element. Index n is actually one of the parameters of the 0...N property of the arguments object.
In JavaScript, you do not need to
HTML uses input to prevent carriage return submission
By default, a single input box, regardless of the button's type= "Submit" or a type= "button" type, is submitted by carriage return.
1. When the type= "submit", no matter how many type= "text"
When using JS to display the date time, the display of the year in Chrome is incorrect (as shown below), but is normal in IE. For example, the current year is 2014, and the number is displayed at 114.
It seems that the Chrome browser and IE
Example 1
The basic idea is to turn the floating-point numbers into integers and divide them by the N-order of the equivalent 10. n is (the sum of the back lengths of two floating-point numbers).
code is as follows
copy code
The method of JavaScript decimal rounding.
Js:
The code is as follows
Copy Code
function Truncatenumber (n) {return n|0;}
Test:
The code is as follows
Copy Code
Console.log
This is really the final mystery of the play window Oh, poof ~, previously wrote an "Ultimate bullet window solution, the human can no longer stop the window!" ", the ultimate version incredibly still have loopholes, helpless can only find another
Regular expression pattern matching JavascriptSummary: Collects some commonly used regular expressions.Regular expressions are used for string processing, form validation, and so on, practical and efficient, but often not too sure to use, so it is
Non-organized functions
When I first started writing JavaScript functions, this is usually the case:
The code is as follows
Copy Code
function Fun1 () {Some code here}function fun2 () {Some other code here}...
Defining arrays
The code is as follows
Copy Code
var a = new Array ("A", "B", "C");Method 1.var mycars=new Array ()mycars[0]= "Saab"mycars[1]= "Volvo"mycars[2]= "BMW"
Method 2.
Define and initialize together:
It's a bit of a hassle to compare the members of two objects in JavaScript, but if it's just the first level comparison, it's easy, but the attributes in the child object may be an object, so you can only recursively
The code is as
Cases
The code is as follows
Copy Code
function CPos (x, y){this.x = x;This.y = y;}function Getobjpos (obj)//Get the position of the control{var target = obj;var pos = new CPos (target.offsetleft,target.offsettop);var
Instance 1
The code is as follows
Copy Code
function getquerystring (name) {var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)");var r = window.location.search.substr (1). Match (REG);if (R!= null)Return unescape (r[
isNaN functionisNaN (expression:object): Boolean
Evaluates the argument and returns True if the value is NaN (non-numeric). This function can be used to check whether a mathematical expression was successfully evaluated as a number.
The isNaN
JS acquisition method.
The code is as follows
Copy Code
document.getElementById ("Divfloat"). Style.top=document.getelementbyid ("button"). offsetleft+25;
With IETester and Firefox test, under the ie6+ can, as
The code is as follows:var flower={};Flower.name= "OOP";Delete Flower.name; Truealert (flower.name); Undefined
Create an object named FlowerFlower has member name, value "OOP";Delete operation deletes this memberDeletion succeeded, no longer exists
I. Function creation processBefore learning about the prototype chain, let's take a look at what a function does during creation. Let's take an example of an empty function:Function (){};When we declare such an empty function in the code, the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service