【问题标题】:load JQuery with MasterPage C#使用 MasterPage C# 加载 JQuery
【发布时间】:2013-10-08 11:53:14
【问题描述】:

我在下面使用这个代码,它的操作是正常的,但是当与 MasterPage 一起使用时,它的行为有严重的问题,代码不起作用。

/// 脚本 /////

$(".cssopen").click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        //var id = $(this).attr('href');
        //alterado
        var id = '.window';

        var body = $("html");
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect        
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //inserido 
        href = $(this).attr("href");
        $('.window').load(href);      

        //transition effect
        $(id).fadeIn(2000);

        //$(id).show();
        $(id).show().position({ my: "center", at: "center", of: "html" });
    });

    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });

    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });

///////////// 代码.aspx ////////////////

<div>
        <asp:ImageButton ID="imgBtCmd" runat="server" ImageUrl="~/Image/edit.png" href="frmIndexII.aspx" CssClass="cssopen"/>

</div>

【问题讨论】:

  • 你能解释一下那些“严重的问题”吗……
  • 母版页将更改控件的 ID,因此请通过 ClientID 获取它们。
  • its behavior has serious problems 没有足够的信息来开始诊断问题,我不禁指出你在这里实际上没有问过问题,只是(很差地)描述了一个问题。你有什么问题?
  • @Sam - 他通过类名而不是 ID 引用图像按钮。这一个措辞糟糕的问题,没有足够的信息来猜测:)
  • 啊,是的,经典的“已损坏请修复”错误。请允许我在这里看看我的水晶球。

标签: c# jquery


【解决方案1】:

我不确定您是否已发布所有所需的信息,但我有根据地猜测您正在使用 jQuery 通过 ID 获取控件,并且自从引入母版页以来,这已经破坏了。这是因为母版页会更改呈现的 HTML 元素的客户端 ID。

如果您使用 .net4 或更高版本,则可以使用

<asp:SomeControl ClientIdMode="static">

并且控件将保留其 Id 客户端。或者,您可以向控件添加一个类,然后按类而不是 ID 对它们进行 jQuery。

【讨论】:

  • 他按类引用按钮,而不是 ID。
  • 好吧,如果你想挑剔的话,他指的是 ID 称为 $('#mask') 的东西。 “我添加了一个母版页,它破坏了我所有的 jquery 选择器”是一个常见问题,这是最有可能出现的问题。/基于提供的信息的解决方案有点模糊。
  • 我一点也不吹毛求疵。他向我们展示的唯一 asp 是图像按钮,他向其中添加了 CssClass 属性,然后在他的脚本中引用了该类名。请不要建议您看到所有这些,然后无论如何都给出这个答案,因为您没有。
  • 如果没有澄清,这个问题是无法回答的,无论如何都应该搁置。
  • 哦,亲爱的,我不想把它变成争论,但我注意到足以知道这可能是问题并提出了一个合理的解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-12
  • 1970-01-01
  • 1970-01-01
  • 2014-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多