I am trying to change an <a>
tag download attribute value with the input from a user.
The user should be able to enter the file name and then click download. I have searched all over and cannot seem to find the answer. Can you please give me some advice?
HTML:
<input id="filename" type="text" onChange="inputChange(event)"/>
<a download="RENAME-ME.csv" href="#" class="download">
Download your file
</a>
Javascript:
function inputChange(e) {
console.log(document.getElementById("filename").value);
}
答案 0 :(得分:0)
您可以像这样使用jQuery:
$('#filename').on('input', function() {
document.getElementsByClassName("download")[0].download = document.getElementById("filename").value
console.log("File name:" + document.getElementsByClassName("download")[0].download )
});
您可以在JSFiddle
找到小提琴答案 1 :(得分:0)
HTML:
updateProposals() {
this._proposals = this._proposals.filter(...); // or whatever
this.subject.next(Object.assign({}, this._proposals)); // emit completely new value
}
JAVASCRIPT:
<input id="filename" type="text" onChange="inputChange(event)"/>
<a download="RENAME-ME.csv" href="#" class="download" id="button">
Download your file
</a>