jquery中的html,val和text有什么区别? [英] What is the difference between html , val and text in jquery ?

查看:100
本文介绍了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.


这篇关于jquery中的html,val和text有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆