.html () ,. text () and .val () summarizes the differences

.html () ,. text () ,. val () Three methods are used to read the contents of the selected elements;

    .html () is used to read html content element (including html tags);

    .text () is used to read plain text elements, including its descendant elements;

    .val () is used to read the form elements "value" value;

    .html () and .text () method can not be used on the form element, .val () can only be used on a form element;

    .html () method is used when the elements of the set, only read the first element; .val () method and .html () the same, if the application in which the elements of the set, only read the first form element the "value" value, but .text () is not the same, if .text () application on multiple elements, will read the text content of all selected elements;

    .html (htmlString) ,. three methods of text (textString) and .val (value) are used to replace the contents of the selected element, if the three methods used in the multiple elements simultaneously, it will replace all selected elements Content;

    .html () ,. text () ,. val () returns the content can be used to dynamically change the value of a plurality of elements callback function;

Guess you like

Origin www.cnblogs.com/tiandi/p/12119191.html