JavaScript函数在本地工作,但不能在测试部署中工作 [英] JavaScript Functions Working Locally but not in Test deployment

查看:53
本文介绍了JavaScript函数在本地工作,但不能在测试部署中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个按钮,可用来在单击时隐藏或显示页面上的其他元素.

I have a few buttons that serve to hide or reveal other elements on the page when clicked.

按钮的格式如下:

<button type="button" id="BTN" onclick="takeAction()">

JavaScript的格式为:

The JavaScript is of the format:

<script type="text/javascript">
    function takeAction() {
         document.getElementById("ELEMENT1_HDR").style.display = "";
         document.getElementById("ELEMENT1_BODY").style.display = "";
         document.getElementById("ELEMENT2").style.display = "none";
         document.getElementById("ELEMENT3").style.display = "none";
     }
</script>

在本地,这在使用严格的HTML和JavaScript以及其他功能在.aspx.cs文件中使用c#时很好用.

Locally, this works just fine when using strictly HTML and JavaScript, as well as when other features are using c# in the .aspx.cs files.

但是,一旦我发布并通过ip地址访问它,单击按钮就没有效果.在执行检查元素并单击按钮时,出现以下错误:

However, as soon as I publish it and access it via the ip address, clicking the buttons has no effect. When doing an Inspect Element and clicking on the button I receive the following error:

"takeAction"属性的值为null或未定义,不是Function对象

The value of the property 'takeAction' is null or undefined, not a Function object

在我的开发环境中有效,但在模拟的Prod环境中无效,这是我做错了什么?

我尝试将< script> 标记内容放在< header> < body> 标记下发布无差异.Visual Studio会在发布时损坏它吗?

I have tried putting the <script> tag contents under the <header> as well as <body> tags to no variance on publishing. Could Visual Studio be corrupting it on publishing?

以某种方式:当我从page1开始并单击查看"按钮导航到特定记录时,发布的版本将记录视图页面加载到屏幕上,但仍保留page1的名称.在本地完成后,它实际上会更改页面地址-因此,这可能是功能在本地运行但不在发布环境中运行的原因

我选择了在第1页和第2页上都存在的名为 noCanDoYet()的函数,该函数仅调用警报函数并在屏幕上显示以下消息:此功能尚未实现".即使在两个页面上都定义了此功能,我也会遇到相同的错误.

I've selected a function that exists on both page1 and page2, called noCanDoYet() which merely calls the alert function and posts to the screen the message: "This feature is not yet implemented". I get the same error for this function even though it is defined on both pages.

alert("help")仍然有效.

以下导航到特定记录的方法是否会在本地环境所没有的Prod类型环境中引起问题?

protected void navigateView(object sender, EventArgs e)
{
    LinkButton lb = (LinkButton)sender;
    setCurrentlySelectedRecord(lb.CommandArgument);
    setViewEdit("View");
    Server.Transfer("page2.aspx");
}

推荐答案

我认为问题与IE11有关.我刚刚安装了Chrome,一切正常.

I think the problem has to do with IE11. I just installed Chrome, and everything works great.

IE11现在也可以很好地与< meta http-equiv ="x-ua-compatible" content ="IE = edge; charset = UTF-8"/> 在我的< script> 之前.

IE11 now works as well with adding <meta http-equiv="x-ua-compatible" content="IE=edge; charset=UTF-8"/> in the <head> just prior to my <script>.

谢谢@JhWebDevGuy

Thanks, @JhWebDevGuy

这篇关于JavaScript函数在本地工作,但不能在测试部署中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆