当前位置: 代码迷 >> JavaScript >> 求 document.getElementById("brandul").getElementsByTagName("li") 里面的具体值,请看代码更清楚解决办法
  详细解决方案

求 document.getElementById("brandul").getElementsByTagName("li") 里面的具体值,请看代码更清楚解决办法

热度:528   发布时间:2012-04-03 12:38:19.0
求 document.getElementById("brandul").getElementsByTagName("li") 里面的具体值,请看代码更清楚
JScript code
function pubfunction()
                    {
                        var liarr = document.getElementById("brandul").getElementsByTagName("li");
                        for(var i=0;i<liarr.length;i++)
                        {
                            liarr[i].onclick=function()
                            {
                                document.getElementById("brandstyle").style.display="none";
                                document.getElementById("ibay_search_1").innerHTML = this.getAttribute("rel");
                            }
                        }
                            
                    }


HTML code

<span id="ibay_search_1">-</span>
<ul id="brandul">
                        <li><a href="javascript:void(0)" rel="Aprilia" id="brand1" onclick="changemodel('Aprilia');pubfunction()">Aprilia</a></li>
                        <li><a href="javascript:void(0)" rel="BMW" id="brand2" onclick="changemodel('BMW');pubfunction()">BMW</a></li>
                        <li><a href="javascript:void(0)" id="brand3" onclick="changemodel('BUELL');pubfunction()">BUELL</a></li>
                        <li><a href="javascript:void(0)" id="brand4" onclick="changemodel('Ducati');pubfunction()">Ducati</a></li>
                        <li><a href="javascript:void(0)" id="brand5" onclick="changemodel('Honda');pubfunction()">Honda</a></li>
                    </ul>


------解决方案--------------------
getElementsByTagName("a");


------解决方案--------------------
JScript code

function pubfunction()
                    {
                        var liarr = document.getElementById("brandul").getElementsByTagName("li");
                        for(var i=0;i<liarr.length;i++)
                        {
                            liarr[i].onclick=function()
                            {
                                document.getElementById("brandstyle").style.display="none";
                                document.getElementById("ibay_search_1").innerHTML = document.getElementById("ibay_search_1").getElementsByTagName("a")..getAttribute("rel");
                            }
                        }
                            
                    } 
  相关解决方案