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 $.