养生 装修 购物 美食 感冒 便秘 营销 加盟 小吃 火锅 管理 创业 搭配 减肥 培训 旅游

js如何清空多个input输入框的内容

时间:2024-10-04 15:33:20

在js中,可以使用getElementsByClassName方法获得同一类名的多稍僚敉视个input对象。下面小编举例讲解js如何通过类名获得多个input对象。

js如何清空多个input输入框的内容

工具/原料

html+js

代码编辑器:zendstudio10.0

方法/步骤

1、新建一个html文件,命名为test.html,用于讲解js如何通过类名获得多个input对象。

js如何清空多个input输入框的内容

2、在test.html文件内,使用input标签创建多个文本框,用于测试。

js如何清空多个input输入框的内容

3、在test.html文件内,设置input标签的class属性为abc。

js如何清空多个input输入框的内容

4、在js标签内,使用getElementsByClassName方法获得input对象。

js如何清空多个input输入框的内容

5、在js标签内,再通过for循环遍历input对象,将每一个input的背景颜色设置为灰色。

js如何清空多个input输入框的内容

6、在浏览器打开test.html文件,查看结果。

js如何清空多个input输入框的内容

© 一点知识