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
code is as follows
copy code
function CharCount (str) {Replaces characters from a string with a regular match, using match () with a regular match. Length gets the number of occurrences of each characterstr = str.replace (/s/ig,
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
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
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
Process Control statements are critical in JS. The Process Control statements in JS include 7 kinds of statements, such as if condition judgment statement, for Loop statement, while Loop statement, Do......while Loop statement, break statement,
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:
Example 1
The code is as follows
Copy Code
/**Determine the date format entered in the input box is YYYY-MM-DD and the correct date*/function IsDate (sm,mystring) {var reg =/^ (d{4})-(D{2})-(d{2}) $/;var str =
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
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
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
JavaScript has only one numeric type Number, and all numbers in Javascript are represented in IEEE-754 standard format. The precision of floating point numbers is not unique to JavaScript, because some decimals represent infinite digits in binary
1. Obtain the querystring parameter of the urlYou can use either of the following methods to obtain the querystring parameter of a url:1.1 Method 1: Regular Expression Matching// Obtain parameters in the urlFunction getQueryString (name ){Var reg =
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.