[英]How should I specify an item in a checkbox list, when using the dom?
我目前正在使用Access 2003中的VBA來自動使用wordpress編輯器,但是我想擴展自動化范圍,以包括對類別,分類項目等的選擇。即帶有復選框列表。 具有相同結構的示例在此處: http : //devblog.xing.com/frontend/the-checkbox-list/
我的列表基於地理實體的層次結構:在本地數據庫中,我可能具有與位置相關聯的數據:例如阿爾及利亞。 我希望能夠使用(即作為SHDocVw.InternetExplorer)ie.document.what?
我對優雅的方法有些迷惑。 我還沒有嘗試過,但是我想我可以獲取每個selectit類的innerhtml,檢查它是否包含我的關鍵字,如果有的話,請通過一些字符串操作提取輸入ID,然后使用ie.document.getelementbyid (“無論如何”)。單擊“檢查”或“切換”
但是有更好的方法嗎?
(最終,我將不得不研究如何連接到遠程數據庫並從那里的表中拖動tag_id,但是我認為這樣做會更快,尤其是在更大范圍內已經存在自動化功能的情況下)
任何指針表示贊賞!
<ul id="localitieschecklist" class="categorychecklist form-no-clear"
data-wp-lists="list:localities">
<li id="localities-8" class="popular-category">
<label class="selectit">
<input id="in-localities-8" type="checkbox" name="tax_input[localities][]" value="8"> </input>
Africa
</label>
<ul class="children"><li id="localities-96">
<label class="selectit"><input id="in-localities-96" type="checkbox" name="tax_input[localities][]" value="96"></input>
Algeria
</label>
感謝您的幫助@Tim Williams。 我不確定在優雅方面是否可行,但是它是否使我向前邁進,我對列表的層次結構性質有點頭疼,並且時間限制了僅支持層次結構的前兩個層次。 它將立即執行,但是任何其他評論當然都歡迎!
地區
If artClassLocalities <> "" And Not IsNull(artClassLocalities) Then
artClasses = Split(artClassLocalities, ",")
Set Element = .Document.getElementByID("localitieschecklist")
For i = 0 To Element.childNodes.Length - 1 'the element collection represents the globe
'popular category items (6) one for each landmass
Set Landmass = Element.childNodes(i)
'landmass has 2 nodes
'child 1 is the selectitnode node 0 (item 1)
If InStr(1, artClassLocalities, Right(Landmass.childNodes(0).innerText, Len(Landmass.childNodes(0).innerText) - 1)) Then
Call Landmass.childNodes(0).childNodes(0).setAttribute("checked", True)
Else
Call Landmass.childNodes(0).childNodes(0).setAttribute("checked", False)
End If
For j = 0 To Landmass.childNodes(1).childNodes.Length - 1 'the children are the countries
Set Country = Landmass.childNodes(1).childNodes(j) ' a given child is a country
If InStr(1, artClassLocalities, Right(Country.childNodes(0).innerText, Len(Country.childNodes(0).innerText) - 1)) Then
Call Country.childNodes(0).childNodes(0).setAttribute("checked", True)
Else
Call Country.childNodes(0).childNodes(0).setAttribute("checked", False)
End If
'Support for Subregions not yet functional
'For k = 0 To Country.childNodes(1).childNodes.Length - 1
'Set PAndADiv = Country.childNodes(j)
Next
Next
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.