访问内容页面上的元素 [英] Accessing an element on a content page

查看:67
本文介绍了访问内容页面上的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的内容页面上有一个javascript函数来隐藏所有div并显示传入的内容。每次脚本执行时,在尝试通过document.getElementById获取元素时返回null。



I have a javascript function on my content page to hide all divs and show the one passed in. Every time the script executes it returns a null when trying to get the element via document.getElementById.

<div id="Tab2" runat="server"  /div>





我尝试了两种不同的方法来构建div的id而且两者都不起作用。



I have tried two different ways to build the id of the div and neither one works.

function openLink(evt, animName) {
     var i;
     var x = document.getElementsByClassName("diy");
     for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
     }
     var divName = "ctl00_MainContent_" + animName;
     var tst = document.getElementById(divName);
     tst.style.display = "block";
     switch (animName) {
        case "Tab2":
           var el2 = document.getElementById("<%=Tab2.ClientID%>");
           el2.style.display = "block";
           break;
        case "Tab3":
           var el3 = document.getElementById("<%=Tab3.ClientID%>");
           el3.style.display = "block";
           break;
     }


  }





任何想法



我尝试过:





Any thoughts

What I have tried:

("<%=Tab2.ClientID%>



tl00_MainContent_+ animName;


tl00_MainContent_" + animName;

推荐答案

页面渲染后你在浏览器中查看了它的输出吗?



after the page renders have you looked at its output in the browser?

<%= >

是服务器端代码的封装,有助于页面呈现。因此您应该能够在您正在使用的浏览器中查看输出。



我会检查浏览器中的HTML源代码,看看你的第一步是什么。

is an encapsulation for server side code that helps in the page rendering. so you should be able to view the output in the browser you are using.

I would check the HTML source in the browser and see what you are getting as the first step.


这篇关于访问内容页面上的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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