检查 div html 中不包含
我有一个 div 和一些复选框,用于在该 maindiv 内添加一些 html 元素。
当我选中该复选框时,我需要在检查它不包含该元素后附加 。细分 ID 将根据所选复选框的不同而变化。
当我取消选中该复选框时,我需要删除 (如果存在)。
我怎样才能使用 jquery 做到这一点?
I have a div <div id="maindiv"></div>
and some checkboxes to add some html element inside that maindiv.
When i check that checkbox, i need to append <div id="subdiv"></div>
after checking that it doesn't contains that element. The subdiv id will vary according to the checkbox selected.
When i uncheck the checkbox, i need to remove the <div id="subdiv"></div>
if exists.
How can i do it using jquery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
HTML:
我使用数据来进行检查。
Try this:
HTML:
I used data to do the checking.
为什么不在 HTML 中添加
并在需要时隐藏/显示此 div?
Why don't you add
<div id="subdiv"></div>
in your HTML and just hide/show this div when you need it?