通过ID在一行中选择多个元素

通过ID在一行中选择多个元素

本文介绍了通过ID在一行中选择多个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有更好/更干净的方法来完成下面代码中的内容.

I would like to know if there is a better/cleaner way to accomplish what I have in the code below.

var updateJob = function(){
    document.getElementById("jobDescription").style.display = "block";
    document.getElementById("updateButton").style.display = "block";
    document.getElementById("equipmentList").style.display = "block";
    document.getElementById("jobDesc").style.display = "block";
    document.getElementById("equipRan").style.display = "block";
}

如果可能的话,我只希望一行可以取消隐藏所有元素. document.getElementById("jobDescription" +"updateButton" +等等...).style.display =阻止"; ,但是它不起作用.我是JavaScript新手.

I would like to have just one line that will unhide all of the elements if its possible I have tried document.getElementById("jobDescription" + "updateButton" + etc...).style.display = "block"; but it does not work. I am new to JavaScript.

推荐答案

为所有必需的元素提供一个类,然后通过 getElementsByClassName(..)进行选择.

Give all your required elements a class and select them through getElementsByClassName(..).

(也许可以使用jQuery以更少的痛苦完成相同的事情)

(and maybe use jQuery to do the same thing with much less pain)

这篇关于通过ID在一行中选择多个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:49