JavaScript and jquery

Source: Internet
Author: User
Tags button type

JavaScript1. Overview

JavaScript is a scripting language that is Object-and event-driven and has security performance.

2.Grammar

the script in the HTML must be between the <script> and </script> tags.

scripts can be placed in HTML pages in the <body> and sections;

most cases are decentralized in the section, which is better than other code that is loaded for execution.

Cases:

<! DOCTYPE html>

<body>

my Web page

<p id= "Demo" > a paragraph </p>

<button type= "button" onclick= "MyFunction ()" > try </button>

<script> function MyFunction ()

{

document.getElementById ("Demo"). Innerhtml= " my first JavaScript function ";

}

</script>

</body>

2.1 InnerHTML

InnerHTML in JS is bidirectional: Gets the contents of an object or inserts content into an object .

Grammar:

Htmlelementobject.innerhtml=text

Cases:

<div id= "AA" > this is content </div>

available through document.getElementById (' AA '). InnerHTML to get ID to be AA the embedded content of the object;   

You can also insert content on an object:

document.getElementById (' abc '). Innerhtml= ' This is the content being inserted ';

inserts content into an object with an ID of ABC.   

2.2Link Script file

Format:

<script type= "Text/javascript" src= "Xxx.js" ></script>

Note: only scripts in the. js file do not contain HTML tags.

JQuery1: Overview

Jquery is a tool library for JS

2:jquerythe function

HTML Element Selection

HTML Element Manipulation

CSS Actions

HTML Event Functions

JavaScript effects and animations

HTML DOM Traversal and modification

Ajax

Utilities

in addition, Jquery also offers a number of plugins. the most common are the jquery UI and the jquery easyui.

3: ReferenceJquery

<script src= "Jquery-1.10.2.min.js" ></script>

4: Syntax

$ (selector). Action ()

Example:$ (this). Hide ()- hides the current element

$ ("P"). Hide ()- hides all <p> elements

$ ("p.test"). Hide ()- hides all <p> elements of class= "test"

$ ("#test"). Hide ()- hides all elements of the id= "test"

5: About the entry function andJsthe Difference

the entry function for jquery:

$ (document). Ready (function () {

Execute Code

});

Or

$ (function () {

Execute Code

});

JavaScript Entry Functions :

Window.onload = function () {

Execute Code

}

the entry function for JQuery is to execute after all HTML tags (DOM) are loaded.

the window.onload event for JavaScript is to wait until all content, including external images, is loaded before it is executed.

6: Event Handling Differences

Event Source:

Js:document.getElementById ("id")

JQuery:$ ("#id")

Event:

Js:d Ocument.getelementbyid ("id"). onclick

JQuery: $ ("#id"). Click

Note:jQuery events do not take on

Event handlers:

Js:

document.getElementById ("id"). onclick = function () {// statement }

Jquery:

$ ("#id"). Click (function () {// statement });

(6th for reference, link I forgot, who knows the words to help me post)

JavaScript Instance reference: http://www.runoob.com/js/js-examples.html

jquery Example Reference: http://www.runoob.com/jquery/jquery-examples.html

JavaScript and jquery

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.