获取特定类的每个UL元素的ID [英] Get every UL element's ID for a specific class
问题描述
目标:从名为SBUpdater的ul类中获取特定HTML元素ul的id值
Goal: Get a specific HTML element ul's id value from a ul class called SBUpdater
目的:我的程序包含几个服务器URL,并从每个服务器URL解析我需要的特定信息。 ul的每个id包含服务器url的值。我需要获取此ID值,以便我可以更新该特定的ul标记并更新屏幕上的内容(无需刷新页面)。
Purpose: My program contains several server url's and parses specific information that I need from each server url. Each id of a ul contains the value of a server url. I need to take this ID value so i can update that specific ul tag and update the content on the screen (without refreshing the page).
在php文件中我有以下内容:
示例代码:
In a php file I have the following: Example Code:
<ul id="http://server1.com" class="SBUPdater">
<li> ... </li>
</ul>
<ul id="http://server2.com" class="SBUPdater">
<li> ... </li>
</ul>
我需要的是一种从ul标签中获取此id值的方法。
已知:
All I need is a method of getting this id value from the ul tags. Known:
- 标签= ul
- Class = SBUpdater
- ID =?
我想要的是检索每个ul的id值,取所有ul id,执行与它们的功能,然后每10秒重复一次。
What I would like is to retrieve every ul's id value, take all ul id's, perform a function with them, and then repeat the process every 10 seconds.
推荐答案
使用原型库你可以这样做:
With prototype library you would do this:
$$('.SBUPdater').each(function(){
new Ajax.PeriodicalUpdater(this, this.getAttribute('data-url'), {
frequency: 10 // every 10 seconds
});
});
每个 ul
元素将使用 data-url
(不是 id
)属性用于保存服务器脚本的URL。然后该脚本将返回相应的 ul
元素的新内容。
Each ul
element would use the data-url
(not id
) attribute to hold the URL of your server script. That script would then return the new content of the appropriate ul
element.
感谢尼克克拉弗的出色建议
这篇关于获取特定类的每个UL元素的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!