最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Using if statement inside for loop - Javascript - Stack Overflow

programmeradmin3浏览0评论

I have a Javascript For Loop...

var CookieName = "Tab,EduTab,EduTab,user";
var tString = CookieName.split(',');

for(i = 0; i < tString.length; i++){

    if (tString[i] == "EduTab") {
        document.write("<b>"+tString[i]+"<b>"); 
    } else {
        document.write(tString[i]);
    }
}

For some reason it is failing to bold the 'EduTab'. It will either bold the entire array CookieName or none at all. Any help would be awesome. Thanks.

I have a Javascript For Loop...

var CookieName = "Tab,EduTab,EduTab,user";
var tString = CookieName.split(',');

for(i = 0; i < tString.length; i++){

    if (tString[i] == "EduTab") {
        document.write("<b>"+tString[i]+"<b>"); 
    } else {
        document.write(tString[i]);
    }
}

For some reason it is failing to bold the 'EduTab'. It will either bold the entire array CookieName or none at all. Any help would be awesome. Thanks.

Share Improve this question asked Feb 15, 2012 at 17:21 JoeJoe 1,6457 gold badges26 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You aren't closing the <b> tag

document.write("<b>"+tString[i]+"<b>")

should be

document.write("<b>"+tString[i]+"</b>")

You are missing the / in your closing tab </b>

发布评论

评论列表(0)

  1. 暂无评论