문제

I'm trying to seperate a list with a line break but neither "\n" nor a br tag are working. Anybody know why?

var c_list=['One','Two','Three']
for (var x in c_list){
    holder_string += c_list[counter]
    holder_string += "\n"
    counter++
    $("#list").text(holder_string);
}
도움이 되었습니까?

해결책

\n isn't really showed in the browser, other than in the source, and <br /> doesn't work in text() as it doesn't accept html, html() does

var c_list=['One','Two','Three']
for (var x in c_list){
    holder_string += c_list[counter]
    holder_string += "<br />"
    counter++
    $("#list").html(holder_string);
}

Note that you could just do

$("#list").html( c_list.join('<br />') );
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top