动态删除和重写(重置)元素? [英] Delete and Rewrite (reset) Elements Dynamically?

查看:80
本文介绍了动态删除和重写(重置)元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我刚开始学习如何使用复选框切换动态显示/隐藏元素。


i想知道是否可以删除/重写元素而不是简单地显示/隐藏它们。原因是因为在下面的代码中,我通过复选框切换显示/隐藏文件字段...但是,如果文件字段在隐藏之前选择文件,则为文件字段选择的文件仍将保留,如你可以看到当你取消选中复选框以使文件字段重新出现...


i想要重写(或重置)文件字段,如果它被隐藏...请让我知道是否有办法。

展开 | 选择 | Wrap | 行号

解决方案

您可以使用removeChil d使用文档对象模型的方法。请参阅此页这个用于解释。

使用getElementById访问div并将其从它的父级:

展开 | 选择 | Wrap | 行号


感谢您的回复...


i'我试图将这些代码植入我当前的代码中,但没有任何事情发生......我肯定写错了... thi s是我所拥有的:

展开 | 选择 | Wrap | 行号


我在代码中使用的div只是一个例子。当你使用

展开 | 选择 | Wrap | 行号


hi everyone. i just started learning how to dynamically show/hide elements with a checkbox toggle.

i would like to know if it''s possible to delete/rewrite elements instead of simply show/hide them. the reason is because in the following code, i show/hide a file field by checkbox toggle... however, if a file field selects a file before it''s hidden, the file selected for the file field will still remain, as you can see when you uncheck the checkbox to make the file field reappear...

i would like to rewrite (or reset) the file field if it is hidden... please let me know if there is a way.

Expand|Select|Wrap|Line Numbers

解决方案

You can delete elements using the removeChild method using the Document Object Model. See this page and this for an explanation.
Access the div using getElementById and remove it from its parent:

Expand|Select|Wrap|Line Numbers


thanks for replying...

i''ve tried to implament that code into my current code, but nothing is happening... i''m for sure writing it wrong... this is what i have:

Expand|Select|Wrap|Line Numbers


theDiv that I used in my code was just an example. When you use

Expand|Select|Wrap|Line Numbers


这篇关于动态删除和重写(重置)元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆