0
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") 来修复它

但仍然错误。

4

1 回答 1

0

我相信您的问题是您没有创建具有唯一 ID 的文本区域

<textarea name='detail"+i+"' id='detail"+i+"' 

在您的replyMessage函数中,只需确保引用正确的文本区域 ID,它应该可以工作。

var rep = document.getElementById("detail"+i).value;
于 2013-09-27T15:06:49.413 回答