当内容页与母版页在同一级文件夹时,母版页上的控件可以触发.js页上的事件,但当内容页在母版页所在的子文件夹时就缺少对象,这个js是为了弹出一个登录框。。
请高手赐教:
Master代码:<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <link type="text/css" href="StyleSheet.css" rel="stylesheet" />
    <script type="text/javascript" src="JScript.js" ></script></head>
<body onresize="if($('overlay')!=null && $('overlay').style.display == 'block') showDiv('floatDiv');">
<div id="main">
    <form id="form1" runat="server">
    <div id="floatDiv" class="floatDiv" style="display:none; left: 632px; top: -198px;">
    <div class="divTitle" onmousedown="moveDiv(event,'floatDiv');">
    <div style="float:right;text-align:right; height:25px;"></div>
    <div style="float:left; width:250px;">用户登录</div>
    </div>
    <div class="divContent">
    <table width="100%" height="100px">
            <tr><td align="right" style="width: 50px">用户名:</td><td align="left">
                <asp:TextBox ID="tbLogName" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbLogName"
                    ValidationGroup="log">*</asp:RequiredFieldValidator></td></tr>
            <tr><td align="right" style="width: 50px">密码:</td><td align="left">
                <asp:TextBox ID="tbLogPwd" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbLogPwd"
                    ValidationGroup="log">*</asp:RequiredFieldValidator></td></tr>
            <tr>
                <td align="right" style="width: 50px; height: 29px">
                    Cookie:</td>
                <td align="left" style="height: 29px">
                    <asp:DropDownList ID="DropDownList1" runat="server" Width="150px">
                        <asp:ListItem Value="0">不保存Cookie</asp:ListItem>
                        <asp:ListItem Value="24">1天内不再登录</asp:ListItem>
                        <asp:ListItem Value="168">1星期内不再登录</asp:ListItem>
                        <asp:ListItem Value="672">1个月内不再登录</asp:ListItem>
                        <asp:ListItem Value="-1">永远内不再登录</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>
        </table>
            <asp:Label ID="lblMsg" runat="server" ForeColor="Red"></asp:Label></div>
    <div class="divFoot">
            <asp:Button ID="Button1" CssClass="divButton" runat="server" Text="登录" OnClick="Button1_Click" ValidationGroup="Other" /><input type="button" class="divButton" onclick="closeDiv('floatDiv')" value="取 消" />
    </div>
    </div>    <div>
        <table cellpadding="5" cellspacing="10" style="width: 1000px">
            <tr>
                <td colspan="2" style="height: 20px">
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Panel ID="Panel1" runat="server" Height="20px" Width="100%">
                        <table style="width: 100%; height: 20px">
                            <tr>
                                <td style="width: 350px; height: 20px;">
                                    <asp:HyperLink ID="hlSign" runat="server" NavigateUrl="~/SignUp.aspx">注册</asp:HyperLink>&nbsp;<asp:LinkButton
                                        ID="lbLog" OnClientClick="showDiv('floatDiv');return false;" runat="server">登录</asp:LinkButton></td>
.js代码:
function closeDiv(_sID)
{
var oObj = $(_sID);
var overlay = $("overlay");
// alert(oObj.id);
if(overlay != null)
{
    overlay.style.display = "none";
overlay.outerHTML = "";
    }
oObj.style.display = "none";

}function showDiv(_sID)
{
var arrySize = getPageSize();
var oObj = $(_sID);
var oDiv = $("overlay");
if(oDiv == null)
{
//创建一个DIV,改名为 overlay 这个是透明的层
oDiv =document.createElement("div");
oDiv.id = "overlay";
document.body.appendChild(oDiv);
}
var overlay = $("overlay");
overlay.style.height = arrySize[1];
overlay.style.width = arrySize[0];
//alert(arrySize[1]);
oObj.style.left = arrySize[0] / 2 - 150 ;
oObj.style.top =  arrySize[1] / 2 - 150;

oObj.style.display = "block";
overlay.style.display = "block";
overlay.style.zindex = oObj.style.zindex - 1;
}//取得页面大小
function getPageSize(){

var xScroll, yScroll;

if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}

var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}

// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else { 
pageHeight = yScroll;
} // for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
return arrayPageSize;
}

解决方案 »

  1.   

    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server"> 
        <link type="text/css" href="StyleSheet.css" rel="stylesheet" /> 
        <script type="text/javascript" src="JScript.js" > </script> 
    是不是相对路径的问题?
      

  2.   

    母板页的使用,不是把子页引入到母页,而是把母页应用到子页
    所以你在母板中引用的文件最好用绝对路径
    比如你的: 
    <link type="text/css" href="/StyleSheet.css" rel="stylesheet" />
    <script type="text/javascript" src="/JScript.js" > </script>