This article mainly introduces the method of jquery setting content, the following example shows how to set the content through text (), HTML () and Val () method, everybody refer to use bar
jquery Settings Content-text (), HTML () and Val () We will use the three same methods in the previous chapter to set the content: text ()-Sets or returns the text content HTML () of the selected element ()-Sets or returns the contents of the selected element (package Enclosed HTML tags) val ()-Sets or returns the value of the form field The following example shows how to set the content through the text (), HTML (), and Val () methods: Instance code as follows: $ ("#btn1"). Click (f Unction () {$ ("#test1"). Text ("Hello world!"); $ ("#btn2"). Click (function () {$ ("#test2"). HTML ("<b>hello world!</b>"); $ ("#btn3"). Click (function () {$ ("#test3"). Val ("Dolly Duck"); The callback functions of text (), HTML (), and Val () The three jQuery methods above: Text (), HTML (), and Val (), also have callback functions. The callback function consists of two parameters: the subscript for the current element in the selected element list, and the original (old) value. Then return the string you want to use with the new value of the function. The following example shows the text () and HTML () with callback functions: instance copy code code as follows: $ ("#btn1"). Click (function () {$ (#test1). Text (Fu Nction (i,origtext) {return "old text:" + origtext + "New Text:hello world! (Index: "+ i +");}); $ ("#btn2"). Click (function () {$ ("#test2"). HTML (function (I,origtext) {return "old HTML: + Origtext +" New html:he Llo <b>world!</b> (Index: "+ i +");}); });