javascript - 数据角色中断 "for loop' 为什么

标签 javascript for-loop

将 data-role="listview"添加到此 html 时:

<ul id="mylinks" class="options" data-role="listview">

它打破了我的“for 循环”。我用警报检查了“lis.length”,它仍然保留着数字值。我也在使用 jquery mobile js。

为什么添加数据 Angular 色后我的“for 循环”不起作用以及如何解决这个问题。是否有运行此循环的替代方法。

<script type="text/javascript">
window.onload=function()
{
    var ul = document.getElementById("mylinks");
    var lis = ul.getElementsByTagName("li");
    alert(lis.length);
    var url = "http://" + window.location.host + "/mobile/";
    var NEWurl = "http://www.sportingpulse.com/mobile/";
    for( var i = 0; i < lis.length; i++ );
    {
        lis.item(i).childNodes[0].href = lis.item(i).childNodes[0].href.replace(url,     NEWurl);
        alert("working")
    }
}
</script>

最佳答案

你有一个不受欢迎的分号

for( var i = 0; i < lis.length; i++ );

应该是

for( var i = 0; i < lis.length; i++ )

关于javascript - 数据角色中断 "for loop' 为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11505074/

相关文章:

python - 从另一个数据框中计算 nunique

javascript - jquery ajax POST方法不执行函数

JavaScript/MomentJS : normalizing dates to current year

javascript - Google oauth2 使用 javascript 获取 accessToken

c++ - for循环输出不显示

python - 在 Python 中遍历 JSON 列表时出现问题?

javascript - Angular - 如何强制在页面加载时检查 radio

javascript - bootstrap 4 中 flex-grow div 内的垂直溢出

javascript - 数组中对象属性的总和

java - {} 格式不同?格式化困境