Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the value of li by javascript

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "javascript how to change the value of li", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to change the value of li javascript" this article.

In JavaScript, you can use the innerHTML attribute to change the value of the li tag, which is used to set or return the HTML between the start and end tags of the table row, with the syntax "li tag object [xss_clean] =" changed value ".

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

How to change the value of li by javascript

In js, by getting the li tag object, you can use the innerHTML attribute to change the value of the li tag.

Create a new html file, named test.html, to explain how JS changes the value of the li tag under the ul tag. Create a list using the ul and li tags, and the values of li are test an and test b, respectively. Set the id of the first li tag to mytest, which is mainly used to obtain the li object through this id. Use the button tag to create a button named "change the value of li".

In the test.html file, bind the onclick click event to the button button, and execute the editli () function when the button is clicked.

Create the editli () function, within the function, use the getElementById () method to get the li object through id (mytest), reassign the innerHTML attribute of the li object, and change the value of the li tag.

Open the test.html file in the browser and click the button to see the effect of the implementation.

After clicking the button:

Summary:

1. Create a test.html file.

2. Within the file, create a list using ul and li tags, and create a button button that triggers the execution of the js function.

3. In the js tag, create a js function. In the function, use the getElementById () method to obtain the li object through id, and reassign the innerHTML attribute of the li object to change the value of the li tag.

The above is all the content of the article "how to change the value of li by javascript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report