zoukankan      html  css  js  c++  java
  • masterpage中服务器端控件命名规则和如何用控件名取得document中的对象,用js动态设置控件事件和属性

    1.masterpage中服务器端控件命名规则和如何用控件名取得document中的对象:
    masterpage.ID + "_" + ContentPlaceHolder.ID + "_" + Contols.ID
    for example:
    document.getElementById("MyMaster_DemoPageInput_TextBox1").value
    描述:MyMaster为mastepage ID,DemoPageInput为ContentPlaceHolder ID,TextBox1为内容页中控件名称.

    在js中用服务器控件id取html对象方法:
    html:<asp:TextBox ID="Query" Width="410px"  MaxLength="100" runat="server" ></asp:TextBox>
    function FindControl(typeOfControl, controlName)
    {
    //alert(typeOfControl);
        var searchString = controlName+"$";
        
    var elements = (typeOfControl == null? document.body.all : document.body.getElementsByTagName(typeOfControl);
        
    for (i = 0; i < elements.length; ++i)
        
    {
            element 
    = elements[i];
            
    //alert(element.value);
            if (element.id.search(searchString) >= 0)
            
    {
                
    return element;
            }

        }


        
    return null;
    }


    function ResetInput_local()
    {
        
    var txtInput = FindControl("input""Query"); 
        txtInput.value 
    = "";
        txtInput.focus();
    }



    2.用js动态设置控件事件和属性:
    Html:
    <div id="loadtree" style="500px;"></div>

    Javascript:
    <script type="text/javascript">

        
    function renderTree()
        
    {
              document.getElementById(
    "loadtree").style.display = "none";
              
    var obj =  document.getElementById("seecate");
              obj.style.cursor 
    = "pointer";
              obj.style.color 
    = "Blue";
              obj.attachEvent(
    "onclick",ShowCategory);         
       }
        
       
    </script>


  • 相关阅读:
    [转载] 如何更有效地说服开发人员接受你的BUG?
    Coded UI Demo
    等价类划分坐标图
    如何将Excel中的测试用例导入到QC中
    [转载]使用Team Foundation Server(TFS)进行项目Bug管理
    [转载] C# 自定义事件和委托
    TFS Guide
    二叉树的深度优先递归、非递归遍历、广度优先遍历 实例
    部署PHP+Apache+MySQL在Windows实战之例
    NLB的设置 Windows 2008 Server R2
  • 原文地址:https://www.cnblogs.com/luyinghuai/p/1212695.html
Copyright © 2011-2022 走看看