Javascript 无法使用母版页在ASP.NET中进行上载
下面的代码在独立的web表单页面中工作,但在我将其放入具有母版页的网站时不起作用。使用Chrome开发者工具,我看到jQuery和jQuery.uploadify被加载。加载页面时发生的错误为: 未捕获的TypeError:$(…)。uploadify不是一个函数 第行出现错误:Javascript 无法使用母版页在ASP.NET中进行上载,javascript,c#,jquery,asp.net,Javascript,C#,Jquery,Asp.net,下面的代码在独立的web表单页面中工作,但在我将其放入具有母版页的网站时不起作用。使用Chrome开发者工具,我看到jQuery和jQuery.uploadify被加载。加载页面时发生的错误为: 未捕获的TypeError:$(…)。uploadify不是一个函数 第行出现错误: $("#file_upload").uploadify({ 代码如下: <%@ Page Title="" Language="C#" MasterPageFile="~/Shared/DefaultMaste
$("#file_upload").uploadify({
代码如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/Shared/DefaultMaster.master" AutoEventWireup="true" CodeBehind="UploadUploadify.aspx.cs" Inherits="Impact.Thm.Web.Utilities.UploadUploadify" %>
<asp:Content ID="Content1" ContentPlaceHolderID="DefaultHeaderContent" runat="server">
<link rel="Stylesheet" type="text/css" href="./App_Themes/Uploader/uploadify.css" />
<script type="text/javascript" src="scripts/jquery-1.8.3.js"></script>
<script type="text/javascript" src="./Scripts/jquery.uploadify.min.js"></script>
<title>Testing Uploadify</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="JavascriptContent" runat="server">
<script type = "text/javascript">
$(function () {
$("#file_upload").uploadify({
'auto': false,
'swf': '/Scripts/uploadify.swf',
'uploader': 'UploadifyStatus.ashx'
});
});
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="DefaultContent" runat="server">
<div style="border: thin solid black">
<p><input type="file" name="file_upload" id="file_upload" /></p>
</div>
<p><a href="javascript:$('#file_upload').uploadify('upload','*')">Upload Files</a></p>
</asp:Content>
如何消除此错误,使其看到uploadify函数?我建议将单击事件移动到页面加载事件(使用其他
uploadify
函数),而不是链接本身:
<asp:Content ID="Content2" ContentPlaceHolderID="JavascriptContent" runat="server">
<script type="text/javascript">
$(function() {
$("#file_upload").uploadify({
'auto': false,
'swf': '/Scripts/uploadify.swf',
'uploader': 'UploadifyStatus.ashx'
});
$("#upload-link").click(function() {
$('#file_upload').uploadify('upload','*');
});
});
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="DefaultContent" runat="server">
<div style="border: thin solid black">
<p><input type="file" name="file_upload" id="file_upload" /></p>
</div>
<p>
<a id="upload-link" href="#">Upload Files</a>
</p>
</asp:Content>
要使jQuery.uploadify在使用母版页时工作,我必须添加对javascript文件的引用。将以下内容添加到DefaultMaster.master
<asp:ScriptManager> ...
<Scripts>
<asp:ScriptReference Path="~/Scripts/jquery.uploadify.min.js" />
将事件处理程序放在页面加载上,而不是链接本身。@Santi我不理解你的建议。你能详细说明一下吗?我从[link]()看到我应该从onclick调用uploadify(),而不是href。但这也不起作用,也不能消除错误。我以前从未使用过jQuery。@Santi,如果你建议使用这个`$(窗口).load(函数(){$(“#文件_upload”).uploadify({'auto':false,'swf':'/Scripts/uploadify.swf','uploader':'UploadifyStatus.ashx'});`我已尝试添加
$(窗口)。load()
,但仍然得到未捕获的类型错误:$(…)。uploadify不是函数错误。您的建议更干净,但我仍然存在错误问题。我发现了使用母版页的问题,并将发布解决方案。
Uncaught TypeError: $(...).uploadify is not a function