js 控制下拉菜单刷新的方法
人气:0
思路:母版頁隱藏控件 從内容頁接收值 JS根據接受的值控制菜單項的現實
母版頁:
隱藏控件:
<asp:Label ID="Lbl_X" runat="server" Text="text" style="display:none"></asp:Label>
<asp:Label ID="Lbl_Xn" runat="server" Text="text" style="display:none"></asp:Label>
JS:
<%-- 設置選中--%>
<script type="text/javascript">
var X = document.getElementById('<%=this.Lbl_X.ClientID %>').innerText;
var Xn = document.getElementById('<%=this.Lbl_Xn.ClientID %>').innerText;
var div = document.getElementById(X);
if (div != null) {
div.setAttribute("class", 'nav-top-item current');
}
var div2 = document.getElementById(Xn);
if (div != null) {
div2.setAttribute("class", 'current');
}
</script>
内容頁給母版頁隱藏空間賦值:
//設置母版頁Lable的值,以控制菜單項CSS
Label X = (Label)this.Master.FindControl("Lbl_X");
X.Text = "A";
Label Xn = (Label)this.Master.FindControl("Lbl_Xn");
Xn.Text = "A1";
母版頁:
隱藏控件:
复制代码 代码如下:
<asp:Label ID="Lbl_X" runat="server" Text="text" style="display:none"></asp:Label>
<asp:Label ID="Lbl_Xn" runat="server" Text="text" style="display:none"></asp:Label>
JS:
<%-- 設置選中--%>
<script type="text/javascript">
var X = document.getElementById('<%=this.Lbl_X.ClientID %>').innerText;
var Xn = document.getElementById('<%=this.Lbl_Xn.ClientID %>').innerText;
var div = document.getElementById(X);
if (div != null) {
div.setAttribute("class", 'nav-top-item current');
}
var div2 = document.getElementById(Xn);
if (div != null) {
div2.setAttribute("class", 'current');
}
</script>
内容頁給母版頁隱藏空間賦值:
//設置母版頁Lable的值,以控制菜單項CSS
复制代码 代码如下:
Label X = (Label)this.Master.FindControl("Lbl_X");
X.Text = "A";
Label Xn = (Label)this.Master.FindControl("Lbl_Xn");
Xn.Text = "A1";
加载全部内容