【发布时间】:2018-11-30 00:19:56
【问题描述】:
如何分别清除这些字段?
<div class="form-group">
<label for="lrcfile">Lyrics file (.lrc)</label>
<input type="file" class="form-control-file" id="lrcfile" accept=".lrc" (change)="setLrcFile($event)" >
</div>
<div class="form-group">
<label for="pitchfile">Pitches file (.txt)</label>
<input type="file" class="form-control-file" id="pitchfile" accept=".txt" (change)="setPitchfile($event)">
</div>
lrcfile: any;
pitchfile: any;
设置文件:
setPitchfile(fileInput: any) {
for (var i = fileInput.target.files.length - 1; i >= 0; i--) {
var file = fileInput.target.files[i];
this.pitchfile = file;
}
}
像大多数消息来源推荐的那样,将它们设置为 ' ' 或 null 不会做任何事情。
this.pitchfile = null;
它仍然显示它在那里。在这张图片中,您可以看到我之前选择的 lrc 文件保持原样,并且我没有对 txt 文件进行任何更改,只是为了展示它的外观。
编辑
我确实设法清除了它,但清除的有点太多了。这样我可以清除我所有的 <input> 字段,但我只想要带有 type = "file" 的字段。
在我的HTML 我还有其他<input>'s 喜欢..
<div class="form-group">
<label for="durationText">Song Duration (ms)</label>
<input type="text" class="form-control" [(ngModel)]="durationText" id="durationText" placeholder="Song Duration">
</div>
哪些不是type = "file"。我设法使用jquery 清除了它们。
jQuery('#addNewSongDialog').find("input,textarea,select")
.val('')
.end()
有没有办法使用它来只清除type = "file" 字段?
【问题讨论】:
-
“未选择文件”...嗯,我看不到了。
-
@BenSteward 我只是在展示它是如何保持的以及它应该是什么样子。将编辑帖子。
-
@BenSteward 所以没有办法清除它?
-
我不知道我停止阅读了。不过,您应该继续阅读。