Javascript
Introduction to Javascript
JavaScript is most commonly used as a client side scripting language. This means that JavaScript code is written into an HTML page. When a user requests an HTML page with JavaScript in it, the script is sent to the browser and it's up to the browser to do something with it. JavaScript is a full-featured programming language that allows a developer to perform calculations and handle looping, selection and repetitive tasks, arrays, and manipulation of the browser object model and the document object model.JavaScript can be placed in the head or body tags within an HTML document using script tags. This method of adding JavaScript to a Web page is considered inline scripting. For inline scripting, the general standard is to place the scripts within the head tag. JavaScript code also can reside in a separate file with a .js extension; this method is known as external scripting.
JavaScript code can be written using a text editor, such as Windows Notepad++, or an HTML editor, such as Dreamweaver. The script element is used to contain scripts and has a type attribute that specifies the language used to write the script. The browser uses the value ("text/javascript") specified by the type attribute to read the script.External scripting is more modular than inline scripting, allowing several Web pages to use the functions in the external JavaScript file.JavaScript uses the three basic structured programming control structures: sequential, selection, and iteration.
JavaScript can be placed in the <body> and the <head> sections of an HTML page.In HTML, JavaScript code must be inserted between
<script> and </script> tags.
When using variables, remember the following:
- Variable declarations start with var.
- Variable names can include only letters, numbers, the underscore (_), or a dollar sign ($).
- Variable names cannot start with a number.
- Reserved words cannot be used.
- The assignment operator (=) is used to modify the value of the variable.
jQuery
jQuery is just one among a number of libraries or frameworks available for JavaScript, but it's the most widely used and I've not come across a compelling reason to use another one. There is excellent introductory material at http://www.w3schools.com/jquery/default.asp One of the most difficult things about jQuery is the syntax, even though in reality it's fairly simple: http://www.w3schools.com/jquery/jquery_syntax.asp Note that the "$" character is just the name of a function, but a crucially important one. In particular, it has nothing to do with variables and is not related to the "$" character as used in PHP! It's really useful to get a clear idea of the range of selectors available: http://www.w3schools.com/jquery/jquery_selectors.asp (the "first", "even", "odd" etc. can be especially useful). (The example of how to use the first-child selector, for instance, has a good example of embedded anonymous functions as commonly used in jQuery: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_sel_ullifirstchild) Again, anonymous functions are the usual approach to defining methods that will be called in response to interactive events: http://www.w3schools.com/jquery/jquery_events.asp
No comments:
Post a Comment