如何使用 JavaScript 实时编辑 html 部分?
我有类别列表侧边栏,我想让它可以上下排序,还可以删除其中的一个列表和底部。 这是图像: 示例
HTML 代码:
<div class="side-nav-categories">
<div class="title"><strong>Category</strong></div>
<ul id="category-tabs">
<li><a href="javascript:void" class="main-category"> Web Applications<i class="fa fa-minus"></i></a>
<ul class="sub-category-tabs">
<li><a href="javascript:void">HTML</a></li>
<li><a href="javascript:void">CSS</a></li>
<li><a href="javascript:void">SCSS</a></li>
</ul>
</li>
</ul>
<ul id="category-tabs">
<li><a href="javascript:void" class="main-category">Script<i class="fa fa-minus"></i></a>
<ul class="sub-category-tabs">
<li><a href="javascript:void">Javascript</a></li>
<li><a href="javascript:void">jQuery</a></li>
<li><a href="javascript:void">Angular JS</a></li>
</ul>
</li>
</ul>
<ul id="category-tabs">
<li><a href="javascript:void" class="main-category">Server Script<i class="fa fa-minus"></i></a>
<ul class="sub-category-tabs">
<li><a href="javascript:void">C#</a></li>
<li><a href="javascript:void">PHP</a></li>
<li><a href="javascript:void">ASP.Net</a></li>
</ul>
</li>
</ul>
</div>
I have Category list sidebar and I want to make it sortable up and down, also remove one list of them with bottom.
Here is image:
example
HTML CODE:
<div class="side-nav-categories">
<div class="title"><strong>Category</strong></div>
<ul id="category-tabs">
<li><a href="javascript:void" class="main-category"> Web Applications<i class="fa fa-minus"></i></a>
<ul class="sub-category-tabs">
<li><a href="javascript:void">HTML</a></li>
<li><a href="javascript:void">CSS</a></li>
<li><a href="javascript:void">SCSS</a></li>
</ul>
</li>
</ul>
<ul id="category-tabs">
<li><a href="javascript:void" class="main-category">Script<i class="fa fa-minus"></i></a>
<ul class="sub-category-tabs">
<li><a href="javascript:void">Javascript</a></li>
<li><a href="javascript:void">jQuery</a></li>
<li><a href="javascript:void">Angular JS</a></li>
</ul>
</li>
</ul>
<ul id="category-tabs">
<li><a href="javascript:void" class="main-category">Server Script<i class="fa fa-minus"></i></a>
<ul class="sub-category-tabs">
<li><a href="javascript:void">C#</a></li>
<li><a href="javascript:void">PHP</a></li>
<li><a href="javascript:void">ASP.Net</a></li>
</ul>
</li>
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从元素的 id 中获取该元素:
上面的行只是使用 JavaScript 实时更改了元素内的值。但请记住,您不需要使用
innerHTML
,您可以使用任何您想要的 JavaScript 属性。You can grab the element from its id:
The above line just changed the value inside an element in realtime, using JavaScript. Keep in mind though, that you don't need to use
innerHTML
, you can use any JavaScript attribute that you want.