0

我在下面有一个表单和 2 个 javascript 函数,但在我的控制台中出现 2 个“$ is defined”错误。如何修复下面的这 2 个错误(错误位于该行旁边包含“//err”的行中:

<body>

<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startImageUpload();' class='imageuploadform' >
<p class='imagef1_upload_process' align='center'>Loading...<br/><img src='Images/loader.gif' /><br/></p><p class='imagef1_upload_form' align='center'><br/>
<label>Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><label class='imagelbl'>(jpg, jpeg, pjpeg, gif, png, tif)</label><br/><br/>
<label><input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>
<label><input type='button' name='imageClear' class='imageClear' value='Clear File'/></label>
</p> 
<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>

<script type="text/javascript">
var sourceImageForm; 

function startImageUpload(imageuploadform){
 //err $(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');
  $(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden');
  sourceImageForm = imageuploadform;

      return true;
}

function stopImageUpload(success){
      var result = '';
      if (success == 1){
         result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
      }
      else {
         result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
      }
     //err  $(sourceImageForm).find('.imagef1_upload_process').css('visibility','hidden');
      $(sourceImageForm).find('.imagef1_upload_form').html(result + '<label>Image File: <input name="fileImage" class="fileImage" type="file"/></label><br/><label>(jpg, jpeg, pjpeg, gif, png, tif)</label><br/><br/><label><input type="submit" name="submitImageBtn" class="sbtnimage" value="Upload" /></label><label><input type="button" name="imageClear" class="imageClear" value="Clear File"/></label>');
      $(sourceImageForm).find('.imagef1_upload_form').css('visibility','visible');

      return true;   
}

</script>

</body>
4

3 回答 3

1

$变量最常用于jQuery,您的页面上似乎没有。这不是javascript 的一部分;它是一个图书馆。script如果要使用它,则需要将其包含在标签中。

于 2012-04-12T19:12:10.020 回答
0

如果您使用 jQuery,则需要确保此代码位于您包含 jQuery 的位置之后,并且它不会在 document.ready 之前运行。

于 2012-04-12T19:11:42.580 回答
0

在您的函数上方包含 jQuery。并且,确保它们在页面加载时加载如下:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" />
$(document).ready(function () {
    // FUNCTIONS GO HERE
});
于 2012-04-12T19:16:33.437 回答