JavaScript 运行时错误 'Show' 未定义

标签 javascript jquery asp.net vb.net

当我的数据表加载到我的服务器上时,我试图显示加载 gif。 我从 here 找到了一些代码,但是当我尝试实现它时,我收到运行时错误“Show”未定义。下面是我正在使用的 javascript/jquery 代码

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function ShowProgress() {
    setTimeout(function () {
        var modal = $('<div />');
        modal.addClass("modal");
        $('body').append(modal);
        var loading = $(".loading");
        loading.show();
        var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
        var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
        loading.css({ top: top, left: left });
    }, 200);
}
$('form').live("submit", function () {
    ShowProgress();
});

我的div id正在加载,所以当它遇到javascript中的loading.show()时,就会出错。

<div class="loading" align="center">
    Loading. Please wait.<br />
         <br />
         <img src="gears.gif" alt="" />
        </div>

我正在页面加载事件上注册我的脚本,例如:

 If IsPostBack = False Then
        Dim script As String = "$(document).ready(function () { $('[id*=Button2]').click(); });"
        ClientScript.RegisterStartupScript(Me.GetType, "load", script, True)

    End If

编辑: 我正在编辑它以添加 Css 标记。

<style type="text/css">
.modal
{
    position: fixed;
    top: 0;
    left: 0;
    background-color: black;
    z-index: 99;
    opacity: 0.8;
    filter: alpha(opacity=80);
    -moz-opacity: 0.8;
    min-height: 100%;
    width: 100%;
}
.loading
{
    font-family: Arial;
    font-size: 10pt;
    border: 5px solid #67CFF5;
    width: 200px;
    height: 100px;
    display: none;
    position: fixed;
    background-color: White;
    z-index: 999;
}

如有任何帮助,我们将不胜感激。

最佳答案

您引用的示例正在使用 Bootstrap。您需要在代码中引用 bootstrap javascript 库才能使用 .show() 方法。

这是示例源代码的最上面部分 - 请参阅底行:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="ctl00_Head1"><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="Content-type" content="text/html;charset=UTF-8" /><title>
    Display Loading progress Image when Page loads or does PostBack using ASP.Net
</title><meta http-equiv="Keywords" content="Mudassar,Mudassar Khan, Mudassar Ahmed Khan,asp.net articles,C#.NET Articles,ASP,ASP.NET,C#,VB,CSharp,C Sharp,dotnet,GridView,DropDownList,Visual Studio,AJAX,CSS, CSS3, JavaScript,JQuery,XML,Crystal Reports,SSIS,SSRS,DetailsView,winforms,windows forms,windows application,code samples,.net code examples,WCF tutorial,WebService tutorial,LINQ,,authoring,programming,learning,beginners guide,primer,lessons,school,howto,reference,free,examples,samples,source code,demos,tips,links,FAQ,tag list,forms,Crystal Reports,Reporting,RDLC Reports,ReportViewer,FaceBook,Twiiter,Google, Google Maps" /><meta http-equiv="Description" content="
ASP.NET,C#.NET,VB.NET,JQuery, Json,JavaScript,Gridview,SQL Server,Ajax,jQuery Plugins,jQuery UI,SSRS,RDLC,Crystal Reports,Reports,FaceBook, Twitter, Google, Google Maps, API, Windows Forms, Windows, WinForms, XML,HTML, CSS, CSS3, jQuery demos,code,snippets, examples, articles" /><link rel="alternate" type="application/rss+xml" title="Free ASP.Net Code Snippets, Tutorials, Articles, Technical Stuff, Tips, Solutions and much more. | ASP.Net, C#.Net, VB.Net, AJAX,JQuery, JavaScript, GridView,SQL Server, RDLC, SSRS, Crystal Reports, XML, JSON, FaceBook, Twitter, Google Maps examples" href="/RSS.axd" /><link rel="icon" type="image/x-icon" href="//aspsnippets.com/images/Metro/Blue/ASPSmall.png" /><meta content="Mudassar Ahmed Khan" name="author" /><meta content="index,follow" name="robots" /><meta content="index, follow" name="Googlebot" />


    <!--[if gt IE 8]>
        <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" media="screen" />
    <![endif]-->
    <!--[if !IE]><!-->
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" media="screen" />
    <!--<![endif]-->
    <!--[if lt IE 9]>
        <link rel="stylesheet" href="/Demos/Bootstrap-3.0/css/bootstrap.min.css" media="screen" />
    <![endif]-->

    <link rel="stylesheet" href="//www.aspsnippets.com/Demos/Bootstrap-3.0/css/override.css?15_12_2016" /><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css" media="screen" />
    <!--[if !IE]><!-->
    <link rel="stylesheet" href="//www.aspsnippets.com/Demos/Bootstrap-3.0/media/Above_1024.css?06_05_2014" /><link rel="stylesheet" media="all and (max-width: 767px)" href="//aspsnippets.com/Demos/Bootstrap-3.0/media/below_767.css" />
    <!--<![endif]-->
    <!--[if gt IE 8]>                
        <link rel="stylesheet" href="//aspsnippets.com/Demos/Bootstrap-3.0/media/Above_1024.css?06_05_2014" /><link rel="stylesheet" media="all and (max-width: 767px)" href="//aspsnippets.com/Demos/Bootstrap-3.0/media/below_767.css" /> 
    <![endif]-->
    <!--[if lt IE 9]>
      <link rel="stylesheet" href="//aspsnippets.com/Demos/Bootstrap-3.0/css/IE.css?06_05_2014" />
        <![endif]-->
    <script type="text/javascript" src='//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js'></script>
    <script type="text/javascript" src='//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js'></script>

关于JavaScript 运行时错误 'Show' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44729120/

相关文章:

javascript - 使用 facebook 登录让 typescript 为 Angular 2 项目工作

javascript - Ajax post 带有参数数组,然后在 PHP 中引用

javascript - AngularJS - 动态添加和删除表中的表单字段

jquery - 在 jQuery 中动画打开/关闭表格列

asp.net - 使用 Global.asax 的优点和缺点是什么?

c# - 在特定列中写入 Serilog ASP.NET MVC C#

javascript - 我可以使用JavaScript删除ASP.NET身份验证cookie(.ASPXAUTH)吗?

javascript - 动态添加 html 表单元素和更新的数据被重置

javascript - JQuery Validate 插件有效方法总是返回 true

jquery - 类型错误 : this. getWindow(...).$ 未定义