gpt4 book ai didi

javascript - Uncaught ReferenceError : parseURL is not defined

转载 作者:行者123 更新时间:2023-11-28 21:19:04 27 4
gpt4 key购买 nike

我在文件头的 JavaScript 中定义了一个名为 parseURL 的函数,并且设置了一个按钮,这样当单击它时,它应该调用该函数。但是,由于某种原因,我的调试器告诉我 parseURL 未定义。确切的错误是“Uncaught ReferenceError:parseURL未定义”

<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<link rel="stylesheet" href="../css/style.css" type="text/css" />
<TITLE>
Pic Grabber (javascript)
</TITLE>
<script type="text/javascript" src="linkedURL.js" />

<script type="text/javascript">
var Page = {};
Page.currentURL = null;
Page.link = document.getElementById("link");

/*
###################################
# The function that "doesn't exist"
###################################
*/

function parseURL(){
Page.url = document.getElementById("url").value;

if(!checkValidURL(Page.url)){
alert("Must Enter a valid URL");
}

Page.link.innerHTML = Page.url;

return true;
}

function checkValidURL(url){
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest;
}
else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHttp");
}
else{
alert("FAIL");
}

if (request) {
request.open("GET", url);
if (request.status == 200) {
return true;
}
}

return false;
}

</script>
</HEAD>
<BODY>
<div class="wrap">
<h1><a href="#">My Database</a></h1>
<ul id="menu">
<li><a href="../index.php">Home</a></li>
<li><a href="../upload.php">Upload</a></li>
<li><a href="#">Advanced Search</a></li>
<li><a href="#">My Profile</a></li>
</ul>
<div class="clear"></div>
<div id="left">
<a href="#" id="link"></a>
</div>
<div id="right">
<div class="box">
<form id="input">
<p>URL:</p><br/>
<input type="text" id="url" /><br />

#################################
# This is where the error appears
#################################

<input type="button" id="getButton" value="Get Pics" onclick="parseURL()" />
<input type="button" id="back" value="<< Back" onclick="back()" disabled="true"/>
<input type="button" id="next" value="Next >>" onclick="next()" disabled="true"/>
</form>
</div>
</div>
</div>

</BODY>

</HTML>

看起来这应该是一个简单的修复,但我已经尝试了很多方法,但似乎没有任何效果。如有任何帮助,我们将不胜感激。

最佳答案

移动这个:

<script type="text/javascript" src="linkedURL.js" />

到这里:

<script type="text/javascript" src="linkedURL.js"> </script>
</BODY>

关于javascript - Uncaught ReferenceError : parseURL is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6851254/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com