Html,text,val of JQ

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title>    <Scripttype= ' Text/javascript 'src= ' Http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js '></Script>    <Script>        $(function(){            //-------------------------------jquery html () [parsing HTML tags]            //1. No parameter HTML (): Gets the HTML content of the [first] matching element, which cannot be used in an XML document. But it can be used in an XHTML document, which returns a string            varphtml= $('P'). html ();            Console.log (phtml); //2. Parameter HTML (val): Sets the HTML content of the [each] matching element, which cannot be used in an XML document, but can be used in an XHTML document, the included HTML tags will be parsed, and a jquery object is returned            $('P'). HTML ('<b> was replaced with the demo text of the </b> P element'); //3. The parameter is the HTML of the callback function (funtion (index, HTML) {...}): The first parameter represents the index position of the current element (index starts at 0), and the second parameter represents the HTML text content of the current element            $('P'). HTML (function(index, oldhtml) {return 'Section' + (++index)+oldhtml;            }); //-------------------------------jquery text () [plain text, do not parse HTML tags]            //1. No parameter text (): Gets the contents of the [all matching] element, the result is a text that is composed of the text content contained by the [all matching] element, and returns a string            varphtml= $('P'). text ();            Console.log (phtml); //2. Parameter text (val): Sets the contents of the [all matching] element, the included HTML tag will not be parsed            $('P'). Text ('<b> new </b>text with demo')            //3. The parameter is the HTML of the callback function (funtion (index, HTML) {...}): The first parameter represents the index position of the current element (index starts at 0), and the second parameter represents the HTML text content of the current element            $("P"). Text (function(index,oldtext) {return (++index)+ "." +OldText;             }); //-------------------------------the Val of jquery ()            //1. Returns the first of the matching elements in a collection            varival= $('Input:text'). Val ();            Console.log (ival); //2. Set value values for all matching elements            $('Input:text'). Val ('the account and nickname are duplicated! '); $('Input:text'). EQ (0). Focus (function(){                $( This). Val ("');            }); $('Input:text'). EQ (0). Blur (function(){                $( This). Val ($ ('Input:text'). EQ (1). Val ());    });    }); </Script></Head><Body>    <P>Presentation text for the first P element</P>    <P>Presentation text for the second P element</P>Account Number:<inputtype= "text"value= "Jason">Nickname:<inputtype= "text"value= "Rocky God Sticks"></Body></HTML>

Html,text,val of JQ

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.