使用jquery删除thickbox中的样式表
我有一个部分视图(Partial.ascx
)、两个母版页(Master1.Master
和 Master2.Master
)和两个视图(>Page1.aspx
和 Page2.aspx
) 在我的 asp.net mvc (C#) 应用程序中。我为每个母版页引用了不同的样式表。
当我在母版页为 Master1.Master
的视图 (Page1.aspx
) 中将部分视图 (Partial.ascx
) 显示为厚盒时,我需要使用引用Master2.Master
的样式表覆盖thickbox内元素的样式,而不影响Page1.aspx
元素的样式。
我尝试过:
$("link[href*='style1.css']").remove();
但是这个查询的问题是它反映在 Page1.aspx
视图中,当我关闭页面的厚框或阴影视图时,该页面的样式就会消失。
如何使用jquery覆盖thickbox内元素的样式表而不影响主视图元素?
I have a partial view (Partial.ascx
), two master pages(Master1.Master
and Master2.Master
) and two Views(Page1.aspx
and Page2.aspx
) in my asp.net mvc (C#) application. I have referred different style sheet for each master page.
When i show the partial view (Partial.ascx
) as thickbox in View(Page1.aspx
) whose Master page is Master1.Master
, i need to overwrite the styles of elements inside the thickbox with style sheet referring to Master2.Master
, without affecting the styles of the Page1.aspx
elements.
I have tried like:
$("link[href*='style1.css']").remove();
But the problem with this query is it reflects in Page1.aspx
View, which when i close the thickbox or in the shadow view of the page, the styles of that page are vanished.
How can overwrite the style sheet of elements inside a thickbox using jquery without affecting the main View elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过仅删除其自身厚盒内的样式?类似这样,其中#thickbox 是thickbox 的ID。
$("link[href*='style1.css']", '#thickbox').remove();
Have you tried only removing styles that are within the thickbox it's self? Something like this where #thickbox is the ID of the thickbox.
$("link[href*='style1.css']", '#thickbox').remove();
当浏览器加载页面时,在页面中设置并使用样式。页面渲染后,删除 link 元素不会再产生任何影响,因为所有 css 规则都已在显示的页面中使用。
您可以做的是重构样式表。将其分成不同的css文件,然后根据游览需要加载到视图中。在PHP中,我可以使用简单的
if
来检测页面是通过AJAX加载还是正常请求,这样我就可以根据我的需要加载不同的CSS。我相信应该有简单的方法在 ASP.NET 中执行相同的操作。A style is set and used in the page when the page loaded by browser. After page rendered, removing link element will not affect anything anymore, since all css rules have been used in the displayed page.
What you can do is restructure the stylesheet. Separate it into different css file, then load in view according to tour needs. In PHP, I can put simple
if
to detect if the page loaded by AJAX or normal request, so I can load different CSS according to my needs. I believe there should be simple way to do the same in asp.net.