我有一个返回选择的JavaScript函数

function getage() {
    var selectedAge = selectedYear;
    var selectedAge = "";
    console.log(selectedAge);
    for (var key in selectedAge) { // run for every value in selectedAge
        console.log(key);
        if (selectedBirth.indexOf('20-' + key) > -1){
            if (selectedAge[key].length > 0) { // check if the subarray of selectedAge contains a value (if birth has selected age)
                selectedAge = selectedAge + age[key] + " selectedAge"; // add the age code as well as 'selected age' to return string
            } else {
                selectedAge = selectedAge + birth[key]; // adds only birth name
            }
            selectedAge = selectedAge + "\n" + "\t";
        }
    }
    return selectedAge;
}


任何帮助,将不胜感激!

最佳答案

如果要换行...


在HTML代码(或一般字符串)中,使用\n
在HTML输出中,使用<br/>标记
在HTML代码及其输出中,将它们组合起来(例如<br/>\n

09-25 16:43