Val (); HTML ();. Text () distinguishes between SetInterval and settimeout

Source: Internet
Author: User
Tags set time

For the innerHTML property, almost all elements have a innerHTML property, which is a string that sets or gets the HTML that is inside the object's start and end tags. (Gets the contents of the beginning and end of the current HTML tag)

For the InnerText property: the content from the starting position to the terminating position, but it removes the HTML tag (only in IE)

Note: The InnerHTML attribute is only available in JS, not in jquery, if you want to use $ ("#t"). HTML ("Sdsds"); or $ ("#t") [0].innerhtml= "Sdsds";

innerHTML is a standard-compliant attribute, and innertext only works with Internet Explorer, so use innerHTML as much as possible, and less innertext

<td>Lastname</td> Firstname Lastname 2

jquery Encapsulation Method Html,text,val

. HTML () HTML tags for reading and modifying elements
. text () to read or modify the plain text content of an element
. val () is used to read or modify the value of the table cell element.

<script src= "/jquery/jquery-1.11.1.min.js" ></script>
<script>
$ (document). Ready (function () {
$ ("#btn1"). Click (function () {
Alert ($ ("#test"). Text ()); Result: This is the bold text in the paragraph
});
$ ("#btn2"). Click (function () {
Alert ($ ("#test"). html ()); Result: This is the <b> bold </b> text in the paragraph
});
});
</script>

<body>
<p id= "Test" > This is the <b> bold </b> text in the paragraph. </p>
<button id= "BTN1" > Display text </button>
<button id= "BTN2" > Show html</button>
</body>

The difference between----setinterval and settimeout

When you make a Web page dynamic, you're bound to meet some requirements that require a program to wait a long time before it starts to execute, just like in our life, and then start doing something later. In JavaScript mainly through the timer to achieve such requirements, this article will make a summary of the timer, is a detailed usage summary of settimeout ().

I. The difference between setinterval and settimeout

SetInterval

The SetInterval () method invokes a function or evaluates an expression (in milliseconds) in the specified period.

Grammar:

SetInterval (function expression, number of milliseconds);

SetInterval () will not stop calling functions until Clearinterval () is called or the window is closed, and the ID value returned by setinterval () can be used as a parameter to the Clearinterval () method.

SetTimeout

The SetTimeout () method is used to call a function or evaluate an expression (in milliseconds) after a specified number of milliseconds

Grammar:

SetTimeout (function expression, number of milliseconds);

SetTimeout () Executes functions only once, and if multiple calls are required, setinterval () can be used, or setTimeout () is called again in the function body

Difference

As can be seen from the above analysis, the main differences between SetTimeout and SetInterval are:

The SetTimeout () method runs only once, which means that when the set time is reached, the specified code is run, the end is finished, and if you want to execute the same function again, you can call SetTimeout () again in the body of the function to achieve the effect of the loop call.

SetInterval () is a loop execution that executes the corresponding function or expression every time the specified interval is reached, and is the real timer.

Two. Use of SetTimeout ()

First write the simplest demo, as follows:

  

1 <! DOCTYPE html> 2  

The page will pop up after 2 seconds, note that settimeout will not be repeated automatically!

Of course, settimeout can also perform function, and can be repeatedly executed!

You can see the text numbers in the H1 increment in one second!

More flexible is that you can also specify the number of times to repeat execution, as follows:

The number in the If judgment is the condition used to limit the number of repeated executions.

Three. Cleartimeout ()

To use Cleartimeout (), we need to set settimeout (), give this settimeout () a name, this name is Timeoutid, when we stop, is to use this timeoutid to halt

1  <! DOCTYPE html> 2   

The warning box that popped up after 1 seconds was halted by nature.

Val (); HTML ();. Text () distinguishes between SetInterval and settimeout

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.