是否可以使用 JavaScript 从 Html 页面指定文件的下载位置?
下面提供了我目前用来关闭我的文件的功能。
function saveTextAsFile()
{
var textToWrite = document.getElementById("inputTextToSave").value;
var textFileAsBlob = new Blob([textToWrite], {type:'xlsx'});
var fileNameToSaveAs = "NAME.csv";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
window.URL = window.URL || window.webkitURL;
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
Run Code Online (Sandbox Code Playgroud)
提前感谢您的帮助。
是否可以在每次保存时覆盖文件.我在html中有一个textarea,我使用JavaScript将文本保存到文件中.它目前保存为:test.txt,test(1).txt,test(2).txt.是否可以在每次下载时保存test.txt.
我用来下载的代码如下:
function saveTextAsFile()
{
var textToWrite = document.getElementById("inputTextToSave").value;
var textFileAsBlob = new Blob([textToWrite], {type:'plan/text'});
var fileNameToSaveAs = "test.txt";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "My Hidden Link";
window.URL = window.URL || window.webkitURL;
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我正在尝试遍历html中的所有ID字段,并使用JavaScript将它们打印到文本字段.这就是我所拥有的:感谢您的帮助:-)
**看起来您的大多数问题都是代码,请提供更多详细信息**
<html>
<head>
<title>Modifying Sentiment</title>
</head>
<body>
<body bgcolor="#E6E6FA">
<font color=black size=+3>Modifying Sentiment</font>
<table>
<tr><td>Text to Save:</td></tr>
<tr>
<td colspan="3">
Add positive adjective:
<img Adjective src="http://findicons.com/files/icons/2776/android_icons/96/ic_question_mark.png" alt="question" title="Adjective: is a word naming an attribute of a noun, such as sweet, red, or technical."
width=20 />
<br>
<textarea cols=40 rows=3 id="textBox1" ></textarea>
<p>
<textarea id="textBox2" style="width:512px;height:256px"></textarea>
</td>
</tr>
<tr>
<td>Filename to Save As:</td>
<td><input id="inputFileNameToSaveAs"></input></td>
<td><button onclick="saveTextAsFile()">Save Text to File</button></td>
</tr>
<tr>
<td>Select a File to Load:</td>
<td><input type="file" id="fileToLoad"></td> …Run Code Online (Sandbox Code Playgroud)