急! 如何取得当前页面上自定义属性controltype的值='aa'的所有元素集合?

fcsoft01 2005-04-04 12:37:17
up
...全文
136 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
meizz 2005-04-04
  • 打赏
  • 举报
回复
<SCRIPT LANGUAGE="JavaScript">
var a = document.all;
var len = a.length;
var b = [];
for (var i=0; i<len; i++)
{
if (a[i].controltype=="aa") b[b.length] = a[i];
}
alert(b.length);
</SCRIPT>
faisun 2005-04-04
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body controltype="aa"><a href="#" controltype="aa">11</a>
<script>

elementsArray=new Array();

function getElementsArray(object){
var i;
var len=object.childNodes.length;
var objectchild;
for(i=0;i<len;i++){ //在子节点中遍历
objectchild=object.childNodes[i];
if(typeof(objectchild.controltype)!="undefined"){
if(objectchild.controltype=="aa"){ //找到元素,加入elementsArray
elementsArray.push(objectchild);
alert(objectchild.outerHTML);
}
}
if(object.childNodes.length>0){ //有子节点,递归查找
getElementsArray(objectchild);
}

}
}

getElementsArray(window.document);
//得到的元素保存在 elementsArray 中
</script>

</body>
</html>
xml <Layer NAME="行政区"> <LayerField Name="XZQDM" Alias="行政区代码" DictionaryName="现状行政区" RelationField="行政区名称" Code="true" ControlType="TreeView" /> <LayerField Name="XZQMC" Alias="行政区名称" DictionaryName="现状行政区" RelationField="行政区代码" Code="false" ControlType="TreeView" /> </Layer> - <Layer NAME="地类图斑"> <LayerField Name="QSXZ" Alias="权属性质" DictionaryName="现状权属性质" RelationField="" Code="true" ControlType="DropDownList" /> <LayerField Name="DLBM" Alias="地类编码" DictionaryName="地类代码" RelationField="地类名称" Code="true" ControlType="TreeView" /> <LayerField Name="DLMC" Alias="地类名称" DictionaryName="地类代码" RelationField="地类编码" Code="false" ControlType="TreeView" /> <LayerField Name="QSDWDM" Alias="权属单位代码" DictionaryName="现状行政区" RelationField="权属单位名称" Code="true" ControlType="TreeView" /> <LayerField Name="QSDWMC" Alias="权属单位名称" DictionaryName="现状行政区" RelationField="权属单位代码" Code="false" ControlType="TreeView" /> <LayerField Name="DLBZ" Alias="地类备注" DictionaryName="现状地类备注" RelationField="" Code="true" ControlType="DropDownList" /> <LayerField Name="JSYDLX" Alias="建设用地类型" DictionaryName="现状建设用地类型" RelationField="" Code="true" ControlType="DropDownList" /> <LayerField Name="KCLX" Alias="扣除类型" DictionaryName="现状扣除类型" RelationField="" Code="true" ControlType="DropDownList" /> <LayerField Name="GDLX" Alias="耕地类型" DictionaryName="现状耕地类型" RelationField="" Code="true" ControlType="DropDownList" /> - <!-- <LayerField Name = "XZGDLY" Alias="新增耕地来源" DictionaryName = "现状新增耕地来源" RelationField="" Code="true" ControlType="DropDownList"> </LayerField> <LayerField Name = "KDPDJ" Alias="耕地坡度级" DictionaryName = "现状坡度级别" RelationField="" Code="true" ControlType="DropDownList"> </LayerField> --> - <!-- <LayerField Name = "ZLDWDM" Alias="座落单位代码" DictionaryName = "现状行政区" RelationField="座落单位名称" Code="true" ControlType="TreeView"> </LayerField> <LayerField Name = "ZLDWMC" Alias="座落单位名称" DictionaryName = "现状行政区" RelationField="座落单位代码" Code="true" ControlType="TreeView"> </LayerField> -->
根据UIAutomation封装了很多自定义方法 现在只需要实例化之后 直接调用方法即可完成。比如单击某个按钮,现在只需要直接调用ClickElement,非常实用。 ClickElement 单击指定的自动化元素 DisselectAllDataGridRow 不选中所有行 DisselectDataGridRow 不选中特定的某一行 FocusWindow 获取窗口焦点 GetAllElement 获取指定父自动化元素下的所有激活的控件 GetAllElementDetails 获取指定自动化元素下的详细信息包括AutomationID,ControlType以及Name GetAllMenus 获取所有菜单项 GetAllSubMenus 获取某个菜单下的所有子菜单项 GetColumnsFromGridLine 获取指定行的所有列 GetColumnValuesFromGridLine 获取行的每一列数据 GetControlType(AutomationElement) 获取制动自动化元素的控件类型 GetControlType(TypeOfControl) 获取UIAutomation的控件类型 GetDocumentText 获取document控件的 GetElementByID 获取父自动化元素下指定元素控件ID的引用 GetElementByName 获取父自动化元素下的指定子元素的引用 GetElementsByControlType 获取父自动化元素下的特定类型的所有自动化元素 GetGridLinesFromDataGrid 获取网格控件的全部行元素的引用 GetHeaderFromDataGrid 获取指定网格控件的标题栏引用 GetMenuBar 获取菜单栏控件 GetMenuByName 通过特定的名称去获取菜单UI自动化元素 GetName 获取指定自动化元素的名称 GetSubMenuByName 获取主菜单下的指定子菜单项的引用 GetValue 获取指定自动化元素 GetWindowByName(String) 获取desktop下的指定窗口名称的子UI自动化元素 GetWindowByName(String, AutomationElement) 获取特定父UI自动化元素下的制定窗口名称的子UI自动化元素 GetWindowList() 获取当前桌面根下所有的UI自动化元素下 GetWindowList(AutomationElement) 获取特定父UI自动化元素下的所有窗口的名称 RefindMainApplication 重新获取desktop下的指定窗口的自动化元素引用 SelectAllDataGridRow 选中所有行 SelectDataGridRow(AutomationElement) 选中特定的某一行 SelectDataGridRow(AutomationElement, Boolean) 将特定的DateGridRow加入选中项中 SelectValueInComboBox 从下拉框中选中指定的项 SelectValueInListBox 从列表中选中指定的项 SetValue 给予指定自动化元素 以上的方法还不是很完善 正在完善中。如果有什么意见和建议,请发送邮件获取 chenxu7601257@qq.com 如果你看了这个帮助文件之后觉得有用的,请发邮件获取,我将把dll文件给你。谢谢。
利用XML文件作的多语言DEMO程序 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' '' '' 多語系設置類 '' '' Create: Bunny_Young 2010-03-12 '' email:yangmeiwen@163.com '' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' Modification history: '' '' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Imports System.Xml Imports System.Data Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.IO Public Class MutiLanguage Const _LANGUAGE_NAME = "language" Const _PAGE_NAME = "pageName" Const _CONTROL_NAME = "controlName" Const _CONTROL_TYPE = "controlType" Const _CONTROL_VALUE = "controlValue" Private _PageName As String ''resource讀取路徑 Private _languageType As String '' Private _xmlDoc As XmlDocument Private _savePath As String Private ds As DataSet Sub New(ByVal strLanguage As String, ByVal aspxPage As String) 'savePath = "~/Resource/" + strLanguage _PageName = "~/Resource/" + strLanguage + "/" + aspxPage + ".xml" _savePath = "~/Resource/" + strLanguage _savePath = HttpContext.Current.Server.MapPath(_savePath) _PageName = HttpContext.Current.Server.MapPath(_PageName) _languageType = strLanguage End Sub Public Sub GetDataSet() ds = New DataSet() ds.ReadXml(_PageName, XmlReadMode.Auto) End Sub Public Function UpdateLanguage(ByVal _controlName As String, ByVal _controlType As String, ByVal _controlValue As String) As Boolean GetDataSet() For Each dr As DataRow In ds.Tables(0).Rows If dr("controlName") = _controlName And dr("controlType") = _controlType Then dr("controlValue") = _controlValue End If Next ds.WriteXml(_PageName, XmlWriteMode.IgnoreSchema) ds.ReadXml(_PageName) End Function Public Function GetControlsList() As List(Of UIControl) GetDataSet() Dim dt As DataTable = ds.Tables(0) Dim ResultList As New List(Of UIControl) For Each dr As DataRow In dt.Rows Dim MyControl As New UIControl MyControl.ControlName = dr("controlName") MyControl.ControlType = dr("controlType") MyControl.ControlValue = dr("controlValue") ResultList.Add(MyControl) Next Return ResultList End Function ''' ''' 主動生成資源文件 ''' ''' 語言類別 ''' WEB PAGE ''' Public Sub WriteResourceFile(ByVal Page As UI.Page) Try If Not Directory.Exists(_savePath) Then Directory.CreateDirectory(_savePath) End If Dim writer As New XmlTextWriter(_PageName, Nothing) writer.Formatting = Formatting.Indented ''語言類別 writer.WriteStartElement(_LANGUAGE_NAME, _languageType) LoopAllControls(Page, writer) ''語言類別結束 writer.WriteEndElement() writer.Close() Catch ex As Exception End Try End Sub Private Sub LoopAllControls(ByVal oCtrl As Control, ByVal writer As XmlWriter) For Each _Ctrl As Control In oCtrl.Controls Dim _strName As String = _Ctrl.GetType.Name.ToUpper If _strName = "LABEL" Or _strName = "BUTTON" Then Dim strValue As String Dim strComment As String If _strName = "LABEL" Then strValue = CType(_Ctrl, Label).Text strComment = "label control" Else strValue = CType(_Ctrl, Button).Text strComment = "button control" End If writer.WriteComment(strComment) writer.WriteStartElement("Control") writer.WriteAttributeString(_CONTROL_VALUE, strValue) writer.WriteAttributeString(_CONTROL_NAME, _Ctrl.ID) writer.WriteAttributeString(_CONTROL_TYPE, _Ctrl.GetType.Name) writer.WriteEndElement() End If If _Ctrl.GetType.Name.ToUpper() = "GRIDVIEW" Then Continue For End If If _Ctrl.HasControls Then LoopAllControls(_Ctrl, writer) End If Next End Sub Public Sub ApplylanguageResource(ByVal _aspxPage As System.Web.UI.Page) GetDataSet() LoopApply(_aspxPage) End Sub Private Sub LoopApply(ByVal _control As Control) For Each ct As Control In _control.Controls Dim controlName As String = ct.ID Dim dr() As System.Data.DataRow = ds.Tables(0).Select("controlName='" + controlName + "'", "controlName DESC") If dr.Count > 0 Then If ct.GetType.Name.ToUpper = "LABEL" Then CType(ct, Label).Text = dr(0)("controlValue") End If If ct.GetType.Name.ToUpper = "BUTTON" Then CType(ct, Button).Text = dr(0)("controlValue") End If End If If ct.HasControls Then LoopApply(ct) End If Next End Sub End Class

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧