无法获得textarea值

时间:2013-09-27 11:41:36

标签: javascript twitter-bootstrap modal-dialog

function getMsgList(){
            var table  = "<tr class='vps_list_head'><th width='20%'>Date</th><th width='70%'>Title List</th>    <th width='10%'></th></tr>";
            for (i=0; i<msgdetail.length; i++){
            table +=    "<tr id='list"+i+"' class='vps_list' >"
                        +"<td class='vps_col' href='#myModal"+i+"' role='button' data-toggle='modal'>"+(msgdetail[i][1]).substring(0,10)+"</td>"
                        +"<td href='#myModal"+i+"' role='button' data-toggle='modal'>"+msgdetail[i][4]+"</td>"
                        +"<td><i class='icon-remove' onclick='delMessage("+msgdetail[i][0]+")'></i></td></tr>"

                        +"<div id='myModal"+i+"' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>"
                        +"<div class='modal-header'>"
                        +"  <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>"
                        +"  <h4 id='myModalLabel'>Title: "+msgdetail[i][4]+"</h4>"
                        +"From : "+msgdetail[i][2]
                        +"<br>Date : "+(msgdetail[i][1]).substring(0,10)
                        +"</div>"
                        +"<div class='modal-body'>"
                        +""+msgdetail[i][5]+""
                        +"</div>"
                        +"<div class='modal-footer'>"
                        +"<div align='center'><textarea name='detail' id='detail' style='margin: 0px 0px 30px 0px;  width: 500px; height: 81px;'></textarea></div>"//This is ploblem.
                        +"  <button class='btn  btn-primary' onclick='replyMessage("+msgdetail[i][0]+")'>Reply</button>"
                        +"  <button class='btn' data-dismiss='modal' aria-hidden='true'>Close</button>"
                        +"</div>"
                        +"</div>"
            }
            document.getElementById('data_msg_order').innerHTML = table;
        }


function replyMessage(i){
        var rep = document.getElementById("detail").value;
                alert(rep);
}

如何从模态中获取价值帮助我。

我尝试使用document.getElementById(“modal”)修复它.getElementById(“detail”)

但仍然是错误。

1 个答案:

答案 0 :(得分:0)

我认为您的问题是您没有使用唯一ID

创建文本区域
<textarea name='detail"+i+"' id='detail"+i+"' 

replyMessage函数中,只需确保引用正确的文本区域ID即可。

var rep = document.getElementById("detail"+i).value;