无法首字母大写,元素未更新

Gre*_*aue 1 html javascript string

我从像这样的textBox中获取我的字符串(在索引递增的循环中):

var name = document.getElementById("TextBox" + index).value;
Run Code Online (Sandbox Code Playgroud)

我的脚本中有一个函数看起来像是大写的第一个字母:

function capital(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}
Run Code Online (Sandbox Code Playgroud)

并试着像这样使用它:

var name = document.getElementById("TextBox" + index).value;
capital(name);
Run Code Online (Sandbox Code Playgroud)

它们在同一script标签中具有不同的功能.我哪里错了?

p.s*_*w.g 5

确保将修改后的值分配回控件:

var element = document.getElementById("TextBox" + index);
var name = element.value;
element.value = capital(name);
Run Code Online (Sandbox Code Playgroud)