JQuery的母版上在ASP.NET中不起作用 [英] JQuery on masterpage doesn't work in ASP.NET

查看:132
本文介绍了JQuery的母版上在ASP.NET中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <link rel="stylesheet" href="css/FirstPage.css" />
    <link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.10.3.custom.css" />
    <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.10.3.custom.js"></script>
  <script type="text/javascript" src="js/slide.js"></script>
<script>
    $(document).ready(function () {
        $("div[id$='slide']").show('bounce');
        $("div[id$='content']").accordion({ fillSpace: true, collapsible: true, active: false });
    });

</script>


在大师身体

在此输入code
          
           
        
         ,但它不工作,这code正是在Web表单里工作,但在母版页不能正常工作?为什么?

推荐答案

您code不是默认Web窗体,因为工作页面(无论是常规页面或母版页)会增加额外的prefixes到控件如果它们被放置正在实施作INamingContainer 接口。

Your code is not working because by default web forms page (be it regular page or master page) will add extra prefixes to the controls if they are placed inside other controls which are implementing INamingContainer interface.

如果你确信你需要 =服务器的属性,你的 DIV s然后可以使用内嵌code和使用客户端ID 属性来获取生成的识别器:

If you are sure that you need runat="server" attribute on your divs then you can use inline code and use a ClientID property to get generated identificator:

$(document).ready(function () {
    $("#<%=slide.ClientID%>").show('bounce');
    $('#<%=content.ClientID%>').accordion({ fillSpace: true, collapsible: true, active: false });
});

另外,您可以使用的 的ClientIDMode 枚举来控制客户端identificators如何选择。在你的情况使用 ClientIDMode.Static

<div runat="server" class="slide" id="slide" ClientIDMode="Static"></div> 

这篇关于JQuery的母版上在ASP.NET中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆