J2EE Review (c) JavaScript (on) - the basis of entry
JavaScript Introduction
JavaScript is a scripting language based on the object for the development based on client and server-based Internet applications can be used to create client-side script and server-side script by Sun Microsystems and Netscape to develop, from the Netscapes developed from Livescript
JavaScript numeric data type (Number) integer or real numbers or Boolean logic (boolean) true or false
String type (String), such as "Hello World", "123.4"
Space type (null) null value, said the special keyword
Arithmetic Operators increase + by - x * In addition to / from a dollar increase of more than% + + a dollar decline --
Equivalent comparison operators: == congruent: === ranges:! = Greater than:> greater than or equal to:> = less than: <less than or equal to: <=
PS: congruent === is the comparison of data types and values, only two are equal only to return true.
Logic and Logical Operators: & & Logical OR: | | logic of non-:!
PS: JavaScript is not & logical
Conditional operator: (condition)? TrueVal: falseVal; example: status = (age> = 18)? "Adult": "minor"
typeof operator: typeof operator to return a string, the string representative of the type of operands;
JavaScript array, there are two ways to assign to the array (you can add any number of values, just as you can define your needs, like any number of variables).
var mycars=new Array(); mycars[0]="Saab"; mycars[1]="Volvo"; mycars[2]="BMW";
You can also use an integer argument to control the capacity of the array:
var mycars=new Array(3); mycars[0]="Saab"; mycars[1]="Volvo"; mycars[2]="BMW";
There is also a definition of the way
var mycars=new Array("Saab","Volvo","BMW"); During his visit to java array is the same with, mycars [0], subscript from 0.
Array of methods and properties using concat () method to merge the two arrays.
Use join () method to all the elements of the array to form a string.
Use sort () method from the literal or numerical sort of array.
JavaScript array length property is also
JavaScript Multi-dimensional array
MyArray = new Array(5,5); MyArray[0, 0] = "Ryan Dias"; MyArray[0, 1] = 1; MyArray[1, 0] = "Mike Donne"; MyArray[1, 1] = 2;
JavaScript try ... catch throw the use of
<html>
<body>
<script type="text/javascript">
var x=prompt("Enter a number between 0 and 10:","")
try
{
if(x>10)
throw "Err1";
else if(x<0)
throw "Err2";
}
catch(er)
{
if(er=="Err1")
alert("Error! The value is too high");
if(er == "Err2")
alert("Error! The value is too low");
}
</script>
</body>
</html> If the value of x is greater than 10 or less than 0, the error will be thrown out (throw). This error was caught after the catch parameter will display an error message from the definition.
JavaScript for ... in statement to use
for ... in statement for each of the attributes in the object, or array cycle between the various elements
<HTML>
<BODY>
<SCRIPT LANGUAGE = "JavaScript">
color = new Array(" Red "," Blue "," Green ");
for (var prop in color){
var record = "color " ;
record+=prop+"="+color[prop] + "<BR>";
document.write(record);
}
</SCRIPT>
</BODY>
</HTML> The use of JavaScript new statement
new operator for the new instance of the object type.
<HTML>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
function employee(name, code, designation) {
this.name = name
this.code = code
this.designation = designation
}
newemp = new employee("John Dias", "A001", " Staff ");
document.write(" Employee names: " + newemp.name + "<BR>");
document.write(" Employee code: " + newemp.code + "<BR>");
document.write(" Title: " + newemp.designation);
</SCRIPT>
</BODY>
</HTML> The use of JavaScript with statement
with statements for the implementation of a set of statements, all of which have assumed that the quoted statement of the object specified.
<HTML>
<BODY>
<SCRIPT LANGUAGE ="JavaScript">
var a, b, c;
var r=10;
with (Math) {
a = PI * r * r;
b = r * cos(PI);
c = r * sin(PI/2);
}
document.write (a +"<BR>");
document.write (b +"<BR>");
document.write (c +"<BR>");
</SCRIPT>
</BODY>
</HTML> JavaScript String Object String Object Example
<HTML>
<BODY>
<script language = "Javascript">
var bstr = " Large numbers ";
var sstr = " Trumpet ";
var blstr = " Bold ";
var blkstr = "Blink" ;
var ucase = " Uppercase ";
var lcase = " Lowercase ";
document.write ("<BR> This is "+ bstr.big() + " Text ");
document.write ("<BR> This is "+ sstr.small() +" Text ");
document.write ("<BR> This is "+ blstr.bold() + " Text ");
document.write ("<BR> This is "+ blkstr.blink() + " Text ");
document.write ("<BR> This is "+ ucase.toUpperCase() + " Text ");
document.write ("<BR> This is "+ lcase.toLowerCase() + " Text ");
</script>
</BODY>
</HTML> Around both ends of the string space approach
<html>
<head>
<title>js String Object</title>
<script language="javascript">
// This is the string class to add three members
String.prototype.Trim = function(){ return Trim(this);}
String.prototype.LTrim = function(){return LTrim(this);}
String.prototype.RTrim = function(){return RTrim(this);}
// Here is an independent function
function LTrim(str)// Removing the left spaces
{
var i;
for(i=0;i<str.length;i++)
{
if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
}
str=str.substring(i,str.length);
return str;
}
function RTrim(str)// Removing the right space
{
var i;
for(i=str.length-1;i>=0;i--)
{
if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
}
str=str.substring(0,i+1);
return str;
}
function Trim(str)// Removal of the left and right sides spaces
{
return LTrim(RTrim(str));
}
</script>
<head>
<body>
<script>alert(" string ".LTrim(this).length);</script>
<script>alert(" string ".RTrim(this).length);</script>
<script>alert(" string ".Trim(this).length);</script>
</body>
</html> JavaScript RegExp (regular expression) object
/** Syntax 1 re = new RegExp("pattern",["flags"]);
Syntax 2 re = /pattern/[flags];
Optional. If you use syntax 2 flag you want to use single quotation marks. Flags can be combined with the available are:
g (Find all occurrences of a pattern)
i (Ignore case)
m (Multi-line find) */
var pattern1 = new RegExp("e","g");
var pattern2 = new RegExp(/^[1-9]\d*$/);
var pattern3 = /^[1-9]\d*$/; RegExp object has three methods: test (), exec () and compile ().
test () method searches the specified string value. Return value is true or false, usually check the legality of the use of strings, such as checking whether the input is floating point value.
exec () method searches the specified string value. Return value is the value to be found. If no match, then return null.
compile () method has been applied to change the RegExp, do not clearly see if the following example.
<html>
<body>
<script type="text/javascript">
function CompileDemo(){
var rs;
var s = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPp";
// Only capital letters create regular expressions.
var r = new RegExp("[A-Z]", "g");
var a1 = s.match(r); // Find matching.
// Only lowercase letters of the compiled regular expression.
r.compile("[a-z]", "g");
var a2 = s.match(r); // Find matching.
return(a1 + "\n" + a2);
}
alert(CompileDemo());
</script>
</body>
</html> JavaScript --- access to event information
JavaScript in: window.event object or event access to event information call access to its key keyCode of the key bit No.
event.keyCode ---- return to the value of the corresponding key bit
event.shiftKey ---- if shift key is touched to return true
event.ctrlKey ---- if ctrl key is touched to return true
touched event.altKey ---- if alt key is to return true
HTML events
onClick --- click event
Double-click the mouse ondblclick ---
onMouseDown --- mouse click
mouse up onMouseUp ---
Right-click the mouse oncontextmenu ---
value change event onChange ---
access to the focus of onFocus ---
onBlur --- loss of focus
mouse onMouseOver ---
left mouse onMouseOut ---
onLoad --- load event
submit event onSubmit ---
Navigator object properties
appCodeName to return to your browser's code name.
appMinorVersion to return to the sub-version of the browser.
appName return the name of the browser.
appVersion browser to return to the platform and version information
browserLanguage browser to return to the current language.
cookieEnabled browser to return to specify whether the value of the opening of Boolean cookie.
system cpuClass browser to return to the CPU level.
to return to onLine specify whether the system is in offline mode boolean value.
platform running the browser to return to the operating system platforms.
Object Navigator
javaEnabled () provided for the opening of the browser is Java.
Window object properties:
closed to return to the window has been closed.
defaultStatus settings or return to the default window status bar text.
document on the Document object of the read-only reference.
history on the History of the read-only object reference.
length set or return the number of window frame.
location for the window or the framework of the Location object.
name set or return the name of the window.
Navigator Object Navigator to invoke the read-only.
return to the opener window of this window to create references.
outerheight window to return to the external high.
outerwidth to return to the external width of the window.
parent to return to the parent window.
Screen on the Screen object read-only reference.
return self reference on the current window. Attribute is equivalent to Window.
Status Bar settings window status text.
top return to top-level window of the ancestors.
window window attribute is equivalent to self attributes, it contains references to the window itself.
Window Object Methods:
alert (string message) a warning message pop-up
confirm (string message) Show a confirmation dialog box
prompt (string prompt [, default]) shows that message and to provide input to the field
atob (decoding string) on the base-64 encoded string to decode
btoa (string) will be base-64 encoding
back () to return to the previous history page
forward () to load the next history page
open (URL, window name [, window specifications])
close ()
focus () focus to the window
blur () the window into the background
stop () to stop loading the page
enableExternalCapture () framework to allow access to the window event
disableExternalCapture () to close enableExternalCapture ()
captureEvents (event type) to capture a particular event window
routeEvent (events) have been sent to capture events
handleEvent (event) so that the entry into force of a specific incident
releaseEvents (event type) to obtain the release of the incident
moveBy (the level of points, vertical points) relative positioning
moveTo (x coordinate, y coordinate) Absolute positioning
home () into the browser's home page
find ([string [, caseSensitivr, backward]]) window to find a specific string
print () Print the contents of the current window.
setHotKeys (true | false) key combination to activate or shut down
setZOptions () set the window stack at the time of the order of overlap
setInterval (expression, milliseconds)
setTimeout (expression, milliseconds)
clearInterval (timer object)
clearTimeout (timer object)
showModalDialog () pop-up modal form, through the mass window.dialogArguments form from the parent to obtain the value, through window.returnValue value to the parent form.
Document Object Properties
body to provide direct access <body> elements. Sets a framework for the definition of the document, the attributes cited in the outermost <frameset>.
cookie settings or return to the current document and all cookie.
domain name to return to the current document.
lastModified return the document was last modified date and time.
referrer to return the documents included in the current document URL.
title to return to the title of the current document.
URL to return to the current document URL.
Document object methods
close () closed by document.open () method to open the output stream, and display selected data.
getElementById () to return to the possession of the specified id of the first object.
getElementsByName () return the name of the object with the specified collection.
getElementsByTagName () return label name with the object of the specified collection.
open () opens a stream to collect from any document.write () or document.writeln () method output.
write () to document the expression or JavaScript to write HTML code.
writeln () equivalent to write () method, different expressions in each write a newline after.
Location object's properties
set to return from the hash or pound (#) to start the URL (anchor).
host set or return the host name and port number of the current URL.
hostname set or return the current URL's hostname.
href settings or return to a complete URL.
set the current pathname or return to the path part of URL.
port settings, or return to the current URL of the port number.
protocol settings, or the agreement to return to the current URL.
search settings, or to return from the question mark (?) started in URL (query part).
Object Location
assign () to load the new document.
reload () to reload the current document.
replace () with a new document to replace the current document.
History Object Properties
length back to the browser's URL history list the number of
History Object
back () to load the list of pre-history of a URL
forward () to load the list of history of the next URL
go () to load the list of history of a specific page
Related Posts of J2EE Review (c) JavaScript (on) - the basis of entry
-
Java Design Pattern Part of the abstract factory pattern
Abstract factory pattern is an abstract factory pattern than an even higher degree of model. In short, the abstract factory class and the factory class of the same principle, only factory class is back in the general category and examples; and return ...
-
Eclipse to run using the specified JVM m2eclipse plugin can not find tools.jar
Used the m2eclipse plug-ins using struts2 when com.sun necessary to rely on the default-tools.jar, specifically because at the struts-annotations bag designated default-tools.jar <profile> <id> default-tools.jar </ id> <activatio ...
-
Pring Beanfactory at the jsp, servlet, web.xml and other configuration
Keywords: spring beanfactory Spring in the web application called the Beanfactory 1) Configure web.xml Java code <? xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE web-app PUBLIC "- / / Sun Microsystems, Inc. / / ...
-
ActiveMQ practice the road (four) ActiveMQ 4.x + JBoss 4.x MDP actual articles
Keyword: ActiveMQ ActiveMQ practice the road (four) ActiveMQ 4.x + JBoss 4.x MDP actual articles At <<ActiveMQ Practice ( Three ) ActiveMQ 4.x +JBoss 4.x Consolidating articles >> which we compare in detail the ActiveMQ with JBoss integra ...
-
Can you understand programming you XP
Agile Extreme Programming XP and RUP (ROSE provide large-scale software development "methodology") are two kinds of software development methodology. Great design is a use of all resources, from the entire field of thought to the design of ...
-
hibernate (jpa) composite primary key annotation statement Ways
hibernate (jpa) composite primary key annotation statement Ways
-
JDBC driver types
1, JDBC is a included in the J2SE and J2EE platform API, you have access to a variety of data sources, in particular, are so typical as Oracle relational database management system. Sun Microsystems Inc. in January 1997 the introduction of JDBC techn ...
-
JAVA interview questions
JAVA interview questions 1, object-oriented features of what has 1. Abstract 2. Inheritance 3. Packaging 4. Polymorphisms 2, String data types are the most basic right? Basic data types include byte, int, char, long, float, double, boolean and short. ...
-
Process migration from tomcat to websphere changes
Process migration from tomcat to websphere changes Because customers use the web application server software used by different what tomcat5, tomcat6, websphere5.1, websphere6.1, weblogic8, and so on, and the software used inconsistent standards, ibm& ...
-
Great collection of java interview topics
1, object-oriented features of what has 1. Abstract: Abstract is that it has overlooked a subject has nothing to do with the current goal of those aspects in order to more fully with the current objectives of the attention-related aspects. Abstract d ...













Leave a Reply