jquery中的html,val和text有什么区别?

jquery中的html,val和text有什么区别?

问题描述:

我在jquery中使用的上述三个属性之间非常困惑,请解释并建议哪一个更有效使用

I am very much confused between above three properties used in jquery please explain and suggest which one is more effeicernt to use

查看此链接 jQuery



html()

获取匹配集中第一个元素的HTML内容。
Check out the this link jQuery.

html()
Obtains the HTML content of the first element in the matched set.


('#Container')。html()



text()--->这是最简单和最常用的

连接包装元素的所有文本内容并将其作为方法的结果返回。这意味着此方法返回我们浏览器上显示的所有字符串。
('#Container').html()

text()---> this is most simple and used
Concatenates all text content of the wrapped elements and returns it as the result of the method. That means this method return all the string which display on our browser.


('#Container')。text()

val()



返回匹配集中第一个元素的value属性。当元素是多选元素时,返回的值是所有选择的数组。此方法仅适用于输入,选择,按钮等控件。它不适用于div,span,p等。
('#Container').text()
val()

Returns the value attribute of the first element in the matched set. When the element is a multiselect element, the returned value is an array of all selections. This method only work with control like input, select, button etc. It not work with div, span, p etc.