gpt4 book ai didi

javascript - 无法调用js文件函数

转载 作者:行者123 更新时间:2023-11-28 07:43:42 25 4
gpt4 key购买 nike

我正在使用一个 js 文件,它在用户 session 即将结束之前给我一个弹出窗口。我以两种方式使用这个文件

1)在网络表单应用程序中 - 它工作得很好。以下是它的代码。我正在关注this链接

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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="Head1" runat="server">
<title>Session Time Out Warning Message</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>

<script src="Script/timeout-dialog.js" type="text/javascript"></script>

<link href="css/timeout-dialog.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" language="javascript">

function Timer(time) {

setTimeout(TimeOut, time);
}

function TimeOut() {
alert(window.location.pathname);
$.timeoutDialog({
timeout: 0.15,
countdown: 60,
keep_alive_url: window.location.pathname,
logout_redirect_url: '/AutoSessionTimeOut/SessionTime.aspx',
restart_on_yes: true
});
}

</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

cs代码:

if (!IsPostBack)
{
int _displayTimeInMiliSec = (Session.Timeout - 1) * 60000;

if (Session["ID"] == null)
{
Session["ID"] = "New Session";
lblMsg.Text = Convert.ToString(Session["ID"]);
}
else
lblMsg.Text = "Old Session";

ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(),
"message",
"<script type=\"text/javascript\" language=\"javascript\">Timer('" + _displayTimeInMiliSec + "');</script>",
false);
}

2) 我在 MVC 应用程序中使用它。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>

<script src="Scripts/timeout-dialog.js"></script>
<link href="Content/timeout-dialog.css" rel="stylesheet" />
<script type="text/javascript">

function Timer(time) {

setTimeout(TimeOut, time);
}

function TimeOut() {
//window.location.pathname = '/Home/Index';
alert(window.location.pathname);
alert('hi');
$.timeoutDialog({
timeout: 0.25,
countdown: 30,
keep_alive_url: window.location.pathname,
logout_redirect_url: '/Home/Index',
restart_on_yes: true
});

}


</script>



</head>
<body onload="Timer(15000)">

<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>

在这里,当我在这条线之前放置一个警报 $.timeoutDialog({ 如上所述,警报出现,但其余代码没有执行,我没有收到任何弹出窗口在我的网络表单应用程序中。

我在 MVC 应用程序中做错了什么。请帮忙。

最佳答案

我认为timeout参数应该是如上所述的整数here

关于javascript - 无法调用js文件函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27700306/

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