【问题标题】:jquery not working in published site but working in development environmentjquery不在已发布的站点中工作,但在开发环境中工作
【发布时间】:2016-01-30 07:42:34
【问题描述】:

我使用 jquery 来更改我的 asp.net 页面的某些元素的样式,如下所示

protected void Page_Load(object sender, EventArgs e)
    {
        string scrp3 = "$(document).ready(function () {if ($('#MainContent_chbkCooperation_1').is(':checked')) {if (!$('#MainContent_chbkCooperation_0').is(':checked')) {$('.pajooheshVal').hide();}}});";
        ScriptManager.RegisterStartupScript(this, GetType(), ClientID, scrp3, true);
    }

在我的本地测试中,这种样式有效,但是当它发布到服务器上时它不起作用,并且样式保持不变。

注意:

我的页面中有多个更新面板并使用 ms-ajax。 如何在页面的每个完整和异步回发中隐藏我的元素?

【问题讨论】:

  • console.log(jQuery) 在生产中为您提供了什么?和错误?
  • Im not sure how to use that command but when i put that in console and test the page something like this showd up , Uncaught Error: selector`选项必须在window.document对象上初始化工具提示时指定!
  • 在控制台中是。它应该给你function(a,b){return new e.fn.init(a,b,h)},这意味着jQuery对象存在并且库加载成功。如果您也有图书馆的 404,请签入网络选项卡。
  • 是的,我得到了 function(a,b){return new e.fn.init(a,b,h)} 但在下一行我也得到了 undefined ,并且在网络选项卡中全部一切都很好,所有状态 ar 200 OK
  • 错误消息听起来像是您正在使用工具提示插件,可能来自引导程序,并且您在文档元素而不是类选择器上对其进行了初始化,因此需要进一步配置。尝试找到发生这种情况的地方并检查工具提示插件的文档以进行正确的初始化。

标签: jquery asp.net ajax webforms


【解决方案1】:

我从客户端解决了这个问题,如下所示:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded);

function PageLoaded(sender, args) {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        if ($('#MainContent_chbkCooperation_1').is(":checked")) {
            if (!$('#MainContent_chbkCooperation_0').is(":checked")) {
                $('.pajooheshVal').hide();
            }
        }
    }

这帮助我在 page 的每个 asyncpostback 上运行 jQuery。 对于完整的回发,我自己使用了 jquery。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 2021-06-17
    • 2014-12-08
    • 1970-01-01
    相关资源
    最近更新 更多