textarea js赋值问题,为什么 value 和 innerHTML 都不行??



 function getMessage()
{
     aContent.length = 0;
     var aTextarea = document.getElementsByTagName('textarea');
     for (var i = 0; i < aTextarea.length; i++) {
        aContent.push(aTextarea[i].value);
    };

    //console.log(aContent)
}


function setMessage()
{
    var aTextarea = document.getElementsByTagName('textarea');

    for (var i = 0; i < aContent.length; i++) {
        console.log(aContent[i]);
        aTextarea[i].innerHTML = aContent[i];
        aTextarea[i].value     = aContent[i];
    };

}

web web前端开发 HTML w3c JavaScript

飞翔的寂寞 10 years, 2 months ago

textarea 标签要使用 innerText 进行设值和取值

AliceBT answered 10 years, 2 months ago

Your Answer