jQuery method to get and set text content

jQuery content text value

Mainly for the content of the element and the value operation of the form.

1. Common element content html() is equivalent to native (innerHTML)

html() //获取元素的内容(包含标签)

$("div").html();//<div>123</div>

html("内容") // 设置元素的内容

$("div").hrml("<strong>123</strong>");

2. Common element text content text() (equivalent to native innerText)

text() //获取元素的文本内容(不含标签)

$("div").text();

text("文本内容")// 设置元素的文本内容

$("div").text("123");

3. The value of the form val() (equivalent to native value)

val()// 获取表单的值

$("input").val();

val("表单的值")// 设置表单的值

$("input").val(123);

Guess you like

Origin blog.csdn.net/qq_46178261/article/details/105692031