How to replace the jQuery library set in the MasterPage, from a Content Page?

久未见 提交于 2019-12-11 19:19:06

问题


I have this problem My project has a master page and content pages, I have in Master Page this code

<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>

but i need use this in only one content page

 <script type="text/javascript" src="js/jquery-1.5.2.min.js"></script>

how I do work ?


回答1:


On your Master Page, add a ContentPlaceHolder to wrap the jQuery library script:

<asp:ContentPlaceHolder ID="jqContentPlaceHolder" runat="server">
    <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
</asp:ContentPlaceHolder>

On every single Content Page that uses the default library, you just ignore the ContentPlaceHolder - by not putting it on the page, because if it's there and it's empty, you'll have no jQuery library whatsoever.

For the page you need a different library, just do this:

<!-- This will replace the default contents set on the Master Page -->
<asp:Content ID="Content1" ContentPlaceHolderID="jqContentPlaceHolder" runat="server">
   <script type="text/javascript" src="js/jquery-1.5.2.min.js"></script>
</asp:Content>



回答2:


Just simply defined the js file link in your content page inside the Head content place holder and it will overload the previous one.



来源:https://stackoverflow.com/questions/18719082/how-to-replace-the-jquery-library-set-in-the-masterpage-from-a-content-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!