1. html () is used to read and modify the HTML tags and content of elements. When html () is used on multiple elements, only the first element is read.
2. text () is used to read or modify the plain text content of elements. The text () method cannot be used on form elements. When text () is applied on multiple elements, the text of all selected elements is read.
3. val () is used to read or modify the value of a form element. val () can only be used on a form element. When the val () method is used on multiple elements, read only the first element.
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "WebForm6.aspx. cs" Inherits = "test2.WebForm6" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
There are two methods in the html attribute: one with a parameter and the other without a parameter.
1. No parameter html (): obtains the html content of the First Matching Element. This function cannot be used in XML documents. But it can be used in XHTML documents and returns a String
2. html (val): sets the html content of each matching element. This function cannot be used in XML documents. But it can be used in XHTML documents. Returns a jquery object.
function htmlAdd() { var div = $("#mydiv").html("<p>OKOKOKOK<P>"); }
Second, there are two methods in the text attribute: one with a parameter and the other without a parameter.
1. No parameter text (): obtains the content of all matching elements. The result is a combination of text content contained by all matching elements. Returns a String
2. text (val): Set the text content of all matching elements, similar to html, however, encode HTML (replace "<" and ">" with the corresponding HTML Entity ). returns a jquery object.
function testAdd() { var div = $("#mydiv").html("<p>OKOKOKOK<P>"); }
Finally, there are two methods in the val () attribute, one with a parameter and the other without a parameter.
1. No parameter val (): obtains the current value of the First Matching Element. In jQuery 1.2, the value of any element can be returned. Including select. If multiple values are selected, an array containing the selected values is returned.
function showVal() { var div = $("#input1").val(); alert("showVal(): " + div); //sumbit }
2. val (val): sets the value of each matching element. In jQuery 1.2, this can also assign values to check, select, and radio elements, and return a jquery object.
function showVal() { var div = $("#input1").val("hahaha"); }