Difference between val() and text()

前端 未结 4 1460
说谎
说谎 2020-11-22 11:50

What the difference between jQuery\'s functions val() and text()?

Where would you use one over the other?

4条回答
  •  借酒劲吻你
    2020-11-22 12:47

    text() return the combined text contents of all matched elements (such as p, div, and so on) val() is used to obtain the value of an input element (such as input, select, and so on)

    according to the official documentation text() should not be used with input elements

提交回复
热议问题