作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个菜单子(monad)菜单和子菜单子(monad)菜单,可以通过单击展开然后显示 - 如果再次单击则显示+显示菜单锁定,例如
-孟加拉国-达卡+兰普拉还显示+美国+澳大利亚等任何一个单击美国然后美国将 - 并显示其城市。但我的代码不能正常工作任何人都可以帮助我吗???
<script language="javascript">
function changeText(idElement) {
var element = document.getElementById('element' + idElement);
if (idElement === 1 || idElement === 2) {
if (element.innerHTML === '+')
element.innerHTML = '-';
else {
element.innerHTML = '+';
}
}
}
</script>
<script language="javascript" type="text/javascript">
$(function () {
$('.submenu1').hide();
$('.submenu2').hide();
$('.submenu3').hide();
$('.submenu4').hide();
$('.submenu11').hide();
$('.submenu').hide();
$('.sub-submenu1').hide();
$('.sub-submenu2').hide();
$('.sub-submenu3').hide();
$('#submenu0').click(function () {
//$('#menu').animate({'height': '200'});
$('.submenu1').toggle("slow");
});
$('#submenu1').click(function () {
//$('#menu').animate({'height': '200'});
$('.submenu2').toggle("slow");
});
$('#submenu-1').click(function () {
//$('#menu').animate({'height': '200'});
$('.submenu11').toggle("slow");
});
$('#submenu3').click(function () {
//$('#menu').animate({'height': '200'});
$('.submenu4').toggle("slow");
});
});
</script>
标清
<ul id="menu">
<li id="submenu0"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Bangladesh</a><br></li>
<li class="submenu1" id="submenu-1"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Dhaka </li>
<li class="submenu11"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Rampura</li>
<li class="submenu11"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Mirpur</li>
<li class="submenu11"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Gulsan</li>
<li class="submenu1"><a id="element1" onClick="javascript:changeText(1)">+</a><a> chittagong </li>
<li class="submenu1"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Rajshahi </li>
<li id="submenu1"><a id="element2" onClick="javascript:changeText(1)">+</a><a> USA</a><br></li>
<li class="submenu2"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Submenu </li>
<li class="submenu2"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Submenu </li>
<li class="submenu2"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Submenu </li>
<li id="submenu2"><a id="element1" onClick="javascript:changeText(1)">+</a><a> India</a><br></li>
<li id="submenu3"><a id="element1" onClick="javascript:changeText(1)">+</a><a> etc many more</a></li>
<li id="submenu4"><a id="element1" onClick="javascript:changeText(1)">+</a><a> Auctions</li>
</ul>
最佳答案
试试这个 Online demo
HTML
<ul class="menu">
<li class="root_ment"><a href="#"><span>+</span>Bangladesh</a>
<ul class="sub_menu" style="display:none;">
<li class=""><a href="#"><span>+</span>Dhaka</a></li>
<li class=""><a href="#"><span>+</span>Rampura</a></li>
<li class=""><a href="#"><span>+</span>Mirpur</a></li>
<li class=""><a href="#"><span>+</span>Gulsan</a></li>
<li class=""><a href="#"><span>+</span>chittagong</a></li>
<li class=""><a href="#"><span>+</span>Rajshahi</a></li>
</ul>
</li>
<li class="root_ment"><a href="#"><span>+</span>USA</a>
<ul class="sub_menu" style="display:none;">
<li class=""><a href="#"><span>+</span>Submenu</a></li>
<li class=""><a href="#"><span>+</span>Submenu</a></li>
<li class=""><a href="#"><span>+</span>Submenu</a></li>
</ul>
</li>
<li class="root_ment"><a href="#"><span>+</span>India</a>
<ul class="sub_menu" style="display:none;">
<li class=""><a href="#"><span>+</span>Submenu</a></li>
</ul>
</li>
<li class="root_ment"><a href="#"><span>+</span>etc many more</a>
<ul class="sub_menu" style="display:none;">
<li class=""><a href="#"><span>+</span>Submenu</a></li>
</ul>
</li>
</ul>
JS
$(".root_ment").click(function(){
if($(this).find("ul").css('display')=="block"){
$(this).find("ul").hide();
$(this).find("span").first().text('+');
}
else{
$(this).find("ul").show();
$(this).find("span").first().text('-');
}
});
关于javascript - 创建菜单子(monad)菜单,单击更改并显示 + - 符号展开与否,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33508199/
我是一名优秀的程序员,十分优秀!