此页面的目标是要求用户使用HTML表单输入URL。这是文档的摘录,位于https://lucasburlingham.github.io/JavaScript-Downloader/index.html:
<body>
<div style="text-align: center">
<h1>JavaScript Downloader</h1>
</div>
<h3>
Enter the URL to download:
</h3>
<input id="url" placeholder="http[s]:// " name="url" style="height: 30px"/>
<input type="submit" onclick="makeRequest(url)" style="text-align: center" class="btn btn-primary form-control">
</form>
</div>
</div>
<br>
<hr>
<br>
<p>
<h4>Need to search something?</h4>
<form method="get" action="http://www.google.com/search">
<input type="text" name="q" size="32" maxlength="255" value="" />
<b><input type="submit" value="Google Search" class="btn btn-primary"/></b>
</form>
<script>
function makeRequest(url) {
var file = new XMLHttpRequest();
file.open("GET", url);
file.responseType = "blob";
file.onload = function() {
onDownloaded();
};
file.send();
</script>
</body>
[按预期,我收到错误,“未捕获的SyntaxError:输入的意外结束”。我在做什么错?
我认为您只是缺少括号来关闭该功能makeRequest
function makeRequest(url) {
var file = new XMLHttpRequest();
file.open("GET", url);
file.responseType = "blob";
file.onload = function() {
onDownloaded();
};
file.send();
}