本文介绍了在鼠标上显示div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我正面临问题; 假设我的文件中有多个div,例如 < div1 > < / div1 > < div4 > < / div4 > < div2 > < / div1 > < div5 > < / div5 > < div3 > < / div1 > < div6 > < ; / div6 > 现在我想做的是当我在div1上滚动我的鼠标时显示div 4的内容,同样当我在div2上滚动我的鼠标时它应该显示有关div 5的信息但是在同时隐藏有关div4的信息等等。我想动态地通过限制使用id来调用每个div上的函数。所以我能够显示它为一个div但是当我去另一个div我必须assi gn新的id,以便我可以使用它的功能。 我的问题还有其他一些方法因为我的div会动态生成所以我不能在运行时添加id。解决方案 是的,您可以在运行时添加ID。我不知道您使用的是哪种语言,但据我所知,您可以使用任何语言添加动态ID(如jsp,php等) 这是您可以使用的示例代码。 < style type = text / css > #div4,#div5,#div6 { visibility:hidden; } < / style > < script > function show(id){ document.getElementById(id).style.visibility =visible; } 函数hide(id){ document.getElementById(id).style.visibility =hidden; } < / script > < div onMouseOver = show('div4') onMouseOut = hide('div1') > < div id = div4 > Div 4内容< / div > < / div > < div onMouseOver = show( 'div5') onMouseOut = hide('div5') > < div id = div5 > Div 5内容< / div > < / div > < div onMouseOver = show('div6') onMouseOut = hide('div3') > < div id = div6 > Div6内容< / div > < / div > hello guys,I''m facing problem;Suppose i have multiple div in my file like<div1></div1> <div4></div4><div2></div1> <div5></div5><div3></div1> <div6></div6>Now what i want to do is to show content of div 4 when i roll over my mouse on div1,similarly when i roll my mouse on div2 it should show info about div 5 but at the same time hiding info about div4 and so on.I want to do it dynamically by limiting use of id to call function on each div.So far iam able to display it for one div but when i go for another div i have to assign new id to it so that i can the function on it. My question is there some other way because my div will be dynamically generated so i cant add id at run time. 解决方案 Yes you can add ID at runtime.I dont know in which language you are working, but as per my knowledge you can add dynamic ID using any language(like jsp,php etc)Here is the Sample code that u can use.<style type="text/css"> #div4, #div5, #div6 { visibility: hidden; }</style><script> function show(id) { document.getElementById(id).style.visibility = "visible"; } function hide(id) { document.getElementById(id).style.visibility = "hidden"; }</script><div onMouseOver="show('div4')" onMouseOut="hide('div1')"> <div id="div4">Div 4 Content</div></div><div onMouseOver="show('div5')" onMouseOut="hide('div5')"> <div id="div5">Div 5 Content</div></div><div onMouseOver="show('div6')" onMouseOut="hide('div3')"> <div id="div6">Div6 Content</div></div> 这篇关于在鼠标上显示div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 06:42