所以我有一个项目列表和一个文本框,我想将隐藏属性应用于与文本框中的内容不匹配的项目。我正在使用 javascript 在浏览器上实时执行此操作。这是我的 HTML(不要担心 g:textbox,我在 grails 中这样做)
Filter List :<g:textBox id = filter onkeyup = Javascript:filter()>
<ul id = 'terms'>
<li id = 'AFUE'>AFUE
<p> Annualized Fuel Utilization Efficiency is a measure of your furnace’s heating efficiency. The higher the AFUE percentage, the more efficient the furnace. The minimum percentage established by the DOE for furnaces is 78.</p>
</li>
<li id = 'Airflow'>Airflow
<p> The distribution or movement of air. </p>
</li>
<li id = 'Air Handler/Coil Blower'>Air Handler/Coil Blower
<p> The indoor part of an air conditioner or heat pump that moves cooled or heated air throughout the ductwork of your home. An air handler is usually a furnace or a blower coil.</p>
</li>
<li id = 'Bioaerosols'>Bioaerosols
<p>Microscopic living organisms that grow and multiply in warm, humid places.</p>
</li>
</ul>
所以我有html设置,现在我需要编写javascript。
1. 我不确定我是否正确使用了 filter.text 并且 2. 不确定如何获取 ul id 中的 li id
function filter(){
// on each li item in ul where ul id = 'terms'
{
if //li item id.match(${filter.text})
{
//li item.hidden = "false"
}
else if !//li item id.match(${filter.text})
{
//li item.hidden = "true"
}
else if ${filter.text} = ""
{
//set all items hidden = "false"
}
}
}
我想说我需要遍历一组元素,但这可能是我身上的红宝石/黄瓜