我已经在 Firefox、IE 和 Chrome 中尝试过,并且使用以下代码,我的警报都没有触发。在页面加载或单击图像时。我对 JavaScript 非常陌生,但非常感谢它在用户体验方面的强大功能。我真的很想更好地学习它,并且希望你们中的一个人能够帮助我理解为什么这不起作用...我将包含完整的 HTML,因为我听说 JScript 来时可能会非常挑剔到选择器和 DOM 对象。我也不知道如何在 javascript 中正确抛出错误... :(
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function preview(img, selection) {
alert("firedTwo");
}
$(document).ready(function () {
alert("firedThree");
});
$(window).load(function () {
alert("fired");
});
</script>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href="../css/profile.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="favicon.ico" >
<link rel="apple-touch-icon" href="apple-touch-icon.png" >
<title>CityGuru.ca - Saskatoon: Profile Editor</title>
</head>
<body>
<h1>Profile Picture Upload</h1>
<div id="subHeader">Upload Picture</div>
<div id="subContainer">
<h2>Create Thumbnail</h2>
<div align="center">
<img src="../images/users/saskatoon/1/photo.jpg" style="float: left; margin-right: 10px;" id="thumbnail" alt="Create Thumbnail" />
<div style="border:1px #e5e5e5 solid; float:left; position:relative; overflow:hidden; width:60px; height:60px;">
<img src="../images/users/saskatoon/1/photo.jpg" style="position: relative;" alt="Thumbnail Preview" />
</div>
<br style="clear:both;"/>
<form name="thumbnail" action="http://saskatoon.CityGuru.ca/includes/profileEditor.php?action=picUpload" method="post">
<input type="hidden" name="x1" value="" id="x1" />
<input type="hidden" name="y1" value="" id="y1" />
<input type="hidden" name="x2" value="" id="x2" />
<input type="hidden" name="y2" value="" id="y2" />
<input type="hidden" name="w" value="" id="w" />
<input type="hidden" name="h" value="" id="h" />
<input type="submit" name="upload_thumbnail" value="Save Thumbnail" id="save_thumb" />
</form>
</div>
<hr />
<h2>Upload Photo</h2>
<form name="photo" enctype="multipart/form-data" action="http://saskatoon.CityGuru.ca/includes/profileEditor.php?action=picUpload" method="post">
Photo <input type="file" name="image" size="30" /> <input type="submit" name="upload" value="Upload" />
</form>
</div>
</body>
</html>
注意
使用 FireFox 的 Web 控制台时,我得到的唯一 JS 错误是$ is not defined