In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to get the value set for span in jquery in the background". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to get the value set for span in jquery in the background".
We will use three identical methods to set up the content:
Text ()-sets or returns the text content of the selected element
Html ()-sets or returns the contents of the selected element (including the HTML tag)
Val ()-sets or returns the value of the form field
1. Html () method
This method is similar to the innerHTML property in js
The $("# two") .html () method gets the html
$("# two") .html ("Hello!")
2. Text ()
Similar to the innerText property in JS
$("div") .text ()? / / get the text content of div
$("div") .text ("Hello!"); / / sets the text content of the div.
3. Val ()
Similar to the value property in JS
$("input [type=text]") .val ()? / / get the value of input
$("input [type=text]"). Val () / / sets the value of input.
The vla () method has another use, that is, it enables the corresponding options for select, checkbox, and radio to be selected.
$(": radio") .val ("Select No. 2") sets the selection value of the radio box whose ID number is single to "Select No. 2"
(": checkbox") .val ("check2,check3") sets multiple options.
The following example shows how to set content through the text (), html (), and val () methods:
Case study
? The code copies the code as follows
$("# btn1") .click (function () {
$("# test1") .text ("Hello world!")
})
$("# btn2") .click (function () {
$("# test2") .html ("Hello world!")
})
$("# btn3") .click (function () {
$("# test3") .val ("Dolly Duck")
})
?
Callback functions for text (), html (), and val ()
The above three jQuery methods, text (), html (), and val (), also have callback functions. The callback function takes two parameters: the subscript of the current element in the selected element list, and the original (old) value. Then return the string you want to use with the new value of the function.
The following example demonstrates text () and html () with callback functions:
Case study
? The code copies the code as follows
$("# btn1") .click (function () {
$("# test1") .text (function (iorigText) {
Return "Old text:" + origText + "New text: Hello world!
(index: "+ I +") "
})
})
$("# btn2") .click (function () {
$("# test2") .html (function (iorigText) {
Return "Old html:" + origText + "New html: Hello world!
(index: "+ I +") "
})
})
Thank you for reading, the above is the content of "how to get the value set for span in jquery in the background". After the study of this article, I believe you have a deeper understanding of how to take the value set for span in jquery in the background, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.