C# 用MasterPage C加载JQuery#
我在下面使用这段代码,它的操作是正常的,但是当使用MasterPage时,它的行为有严重的问题,代码不起作用 ///剧本/////C# 用MasterPage C加载JQuery#,c#,jquery,C#,Jquery,我在下面使用这段代码,它的操作是正常的,但是当使用MasterPage时,它的行为有严重的问题,代码不起作用 ///剧本///// $(".cssopen").click(function (e) { //Cancel the link behavior e.preventDefault(); //Get the A tag //var id = $(this).attr('href'); //alterado
$(".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>
我不确定您是否发布了所有必需的信息,但我有根据地猜测,您正在使用jQuery按ID抓取控件,自从引入母版页以来,这一点已被打破。这是因为母版页将更改呈现的HTML元素的客户端id 如果您使用的是.net4及以上版本,则可以使用
<asp:SomeControl ClientIdMode="static">
控件将保留其客户端Id。或者,您可以向控件中添加一个类,并按类而不是ID查询它们。您能解释一下这些“严重问题”吗?请参见。母版页将更改控件的ID,以便按ClientID获取它们。
其行为有严重问题。
没有足够的信息来开始诊断问题,我忍不住要指出一点,你们在这里并没有提出任何问题,只是(糟糕地)描述了一个问题。你的问题是什么?@Sam-他是按类名而不是ID引用图像按钮的。这是一个措辞糟糕的问题,甚至没有足够的信息来猜测:)啊,是的,经典的“坏了,请修复”错误。请允许我在这里查看一下我的水晶球。他是按类引用按钮,而不是ID。如果你想挑剔的话,他是按ID引用一个名为$(“#mask”)
的东西。“我添加了一个母版页,它破坏了我所有的jquery选择器”是一个常见的问题,这是最可能的问题。/基于提供的信息的解决方案有点模糊。我一点也不挑剔。他向我们展示的唯一一个asp是image按钮,他在其中添加了CssClass属性,然后在他的脚本中引用了该类名。请不要建议你看到所有这些,然后不顾一切地给出答案,因为你没有。没有澄清,这个问题是无法回答的,无论如何应该搁置。哦,亲爱的,我不想把这变成一场争论,但我注意到这可能是个问题,并提出了合理的解决方案