[英]How to dynamically load Li element's with other Javascript Array li
I have a problem figuring out how to make my menu items dynamically change other list items when clicked on. 我在弄清楚如何使我的菜单项在单击时动态更改其他列表项时遇到问题。
For example I want Box1: 例如我想要Box1:
<nav class="left">
<ul>
<li>
<a href=""><br>box1</a>
</li>
...
to update the li's in the 'topnav' class: 更新“ topnav”类中的li:
<header class="topnav">
<ul>
<li><a href="">Item</a></li>
<li><a href="">Item2</a></li>
<li><a href="">Item3</a></li>
</ul>
</header>
so when a user clicks box1 menu item on the left class navigation menu, the for instance - 'Item'/'Item2'/'Item3' list item updates to lets say "NewItemName"/"NewItemName2"/"NewItemName3" 因此,当用户单击左侧类导航菜单上的box1菜单项时,例如-'Item'/'Item2'/'Item3'列表项更新为说“ NewItemName” /“ NewItemName2” /“ NewItemName3”
example codepen: http://codepen.io/anon/pen/Epiom 范例代码笔: http ://codepen.io/anon/pen/Epiom
edit: I am trying to change the li's of (item,item2,item3) with new ones when you click the side bars navigation buttons. 编辑:当您单击侧边栏导航按钮时,我试图用新的更改li(item,item2,item3)。 ex, when you click settings the 3 top buttons(top nav li's) would change to profile settings, video settings, sound settings (these names are made up and not in the code)
例如,当您单击设置时,顶部的3个按钮(顶部导航按钮)将更改为配置文件设置,视频设置,声音设置(这些名称是组成的,不在代码中)
Check this fiddle whose code is also below and tell me if it is what you want 检查这个提琴,其代码也在下面,并告诉我它是否是您想要的
<body>
<header class="topnav">
<ul>
<li><a href="">Item</a>
</li>
<li><a href="">Item2</a>
</li>
<li><a href="">Item3</a>
</li>
</ul>
</header>
<nav class="left">
<ul>
<li>box</li>
<li>otherbox</li>
</ul>
</nav>
<script>
$(function()
{
$(".left li").click(function()
{
var box = $(this).html();
$( ".topnav li a" ).each(function( index )
{
$(this).html("New" + box + "_" + index)
});
});
});
</script>
</body>
EDIT: 编辑:
http://codepen.io/zen_coder/pen/beCKf http://codepen.io/zen_coder/pen/beCKf
If you are just starting front end development you may want to have a look at: 如果您只是开始前端开发,则可能需要看一下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.