Jquery object and native JavaScript Object

Source: Internet
Author: User
Code <! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> automatic line feed </title>
<SCRIPT src = ".../jquery/jquery-1.3.1.js" type = "text/ecmascript"> </SCRIPT>
<Style type = "text/CSS">
* {Margin: 0; padding: 0; Border: 0 ;}
. Text {width: 500px; Height: 500px; margin: 20px auto; Background-color: # CCC; padding: 10px ;}
</Style>
</Head>

<Body>
<P id = "text" class = "text"> warning </P>
<SCRIPT type = "text/JavaScript">
// Jquery objects cannot use native JavaScript objects
// If you want to use the native JavaScript Object method, you can use the get () method to convert the jquery object to the native JavaScript Object.
Function breakwords (maxlen, OBJ ){
VaR text = $ (OBJ). Text (); // The text () method of jquery returns the original string data type, so you can use the native js method.
VaR temp = "";
While (text. length> maxlen ){
Temp + = text. substr (0, maxlen) + "<br/>"; // substr is a native javascript string object method.
TEXT = text. substr (maxlen, text. Length );
};
Temp + = text;
Objects (obj).html (temp); // innerhtml cannot be used here because $ {OBJ} is a jquery object. In addition, the HTML () and text () Methods of jquery objects are different. Here, HTML () is used instead of text ()
}
Breakwords (50, "# text ");
</SCRIPT>
</Body>
</Html>

 

WhenWhen using jquery, you must distinguish whether the current operation object is a jquery object or a native JavaScript Object. Jquery objects can only use methods and attributes defined in jquery, but cannot use methods and attributes of native JavaScript objects. Javascript objects are similar. Of course, jquery objects can be converted to JavaScript objects through the get () method, or jquery objects can be created through $.

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.