search
HomeWeb Front-endHTML Tutorial三级下拉菜单 变量_html/css_WEB-ITnose

function list(idstr){
var name1="subtree"+idstr;  //定义一个变量 值为字符串“subtree”加上传进来的ID 
var name2="img"+idstr;    //idstr是一个数字字符,用于区别不同的子菜单和图片
var objectobj=document.all(name1);//获取页面中ID或者name为name1的元素
var imgobj=document.all(name2);

//判断如果元素的样式为display=="none"
if(objectobj.style.display=="none"){
for(i=1;i var name3="img"+i;//定义一个变量字符串img+1
var name="subtree"+i;
var o=document.all(name); ////获取页面中ID或者name为name的元素
if(o!=undefined){ 
                             //如果元素的值没有定义
o.style.display="none"; //o的样式为隐藏
var image=document.all(name3);
//alert(image);  //吧图片的SRC改为/images/ico04.gif
image.src="/images/ico04.gif";  
}
}
}

}
跪求大神!!!
1、第二行中的 var name1="subtree"+idstr,"subtree"是做什么的啊?
2、 var objectobj=document.all(name1);怎么找会得到 name1("subtree"+idstr),name1都是img*这种格式的?
3、三级下拉菜单跟循环有什么的关系呢?


回复讨论(解决方案)

1."subtree"只是一个名字,是为了方便能取到该元素;
2.注释里面都写了,是为了获取页面中ID或者name为name1的元素,并不是图片格式对它的名字没有影响。
例如:

<img  src="/static/imghwm/default1.png"  data-src="../img/1.jpg"  class="lazy"  id="subtree1" name=""subtree1  alt="三级下拉菜单 变量_html/css_WEB-ITnose" >

3.三级下拉菜单跟循环没什么关系,这里的循环是为了改变相应的图片。

http://www.5imoban.net/texiao/nav/20141031927.html

http://www.jb51.net/article/70912.htm

http://www.17sucai.com/pins/7688.html

1、2问题已经解决。3、那为什么三级下拉菜单能实现点击就出现下面的子菜单?

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.