无法从表格td获取带引号的值

时间:2015-10-02 09:57:33

标签: javascript

这里我正在创建动态表

function addToMLContainer(id, mlName, mlAddress) {
    return '<td><s:text>' + mlName + ' ' + mlAddress + '</s:text></td>' +
        '<td hidden="hidden">' + id + '<input name="mlId" type="hidden"       value = "' + id + '" /></td>' +
        '<td hidden="hidden"><input name="mlFullName" type="hidden" value = "' + mlName + ' ' + mlAddress + '" /></td>' +
        '<td align="center"><img src="/delete.png" class="remove" onclick="this.closest(\'tr\').remove()"/></td>'
}

在这里,我得到了tr的价值:

var t = document.getElementById("AddedMlsContainer");

for (var i = 1, row; row = t.rows[i]; i++) {

    selectedMerchants = selectedMerchants + " " + row.cells[2].children[0].value + "\n";

}

问题是我无法通过<I'm "blabla">

等双引号或单引号获得价值

1 个答案:

答案 0 :(得分:0)

最后我通过删除输入字段和不需要的td:

来完成
'<td>' + mlName + ' ' + mlAddress + '</td>' +
        '<td hidden="hidden">' + id + '<input name="mlId" type="hidden" value = "' + id + '" /></td>' +
        '<td align="center"><img src="/delete.png" class="remove" onclick="this.closest(\'tr\').remove()"/></td>'

然后我使用了innerHtml

var t = document.getElementById(&#34; AddedMlsContainer&#34;);

for (var i = 1, row; row = t.rows[i]; i++) {

    selectedMerchants = selectedMerchants + " " + row.cells[0].innerHTML.replace(/&nbsp;/g,'') + "\n";

}