将新行字符传递给函数javascript

时间:2017-02-23 21:43:21

标签: javascript

我从控制器收到一个数组,我将其放入表中并生成指向"编辑","删除"和"合并"的链接。 "编辑" event将变量传递给函数,该函数打开对话框,其中变量lSynonyms应与表中显示的同义词类似地呈现为多行。我试过了:

lSynonyms += data[i]['varNames'][j]['varTeamID'] + ' > ' + data[i]['varNames'][j]['varName'] + '\r\n';

lSynonyms += data[i]['varNames'][j]['varTeamID'] + ' > ' + data[i]['varNames'][j]['varName'] + '\n';

两者都给我错误"未终止的字符串常量"当我点击"编辑"链接。如果我删除\ r \ n该函数工作正常,但textarea中的数据不会显示为新行。如何正确传递这些新行?

生成表的代码

for (i = 0; i < data.length; i++) {
    var Synonyms = '';
    var lSynonyms = '';
    for (j = 0; j < data[i]['varNames'].length; j++) {
    Synonyms += data[i]['varNames'][j]['varTeamID'] + ' > ' + data[i]['varNames'][j]['varName'] + '<br/>';
    lSynonyms += data[i]['varNames'][j]['varTeamID'] + ' > ' + data[i]['varNames'][j]['varName'] + "\r\n";
    }
$("#teamstable > tbody").append('<tr><td>' + data[i]["stdTeamID"] + '</td><td>' + data[i]["stdName"] + '</td><td>' + Synonyms + '</td><td><a onclick="updateform(' + data[i]["stdTeamID"] + ',\'' + data[i]["stdName"] + '\',\'' + lSynonyms + '\')">edit</a>' + '&nbsp;<a onclick="mergeform(' + data[i]["stdTeamID"] + ')">merge</a>&nbsp;' + '<a onclick="RemoveTeam(' + data[i]["stdTeamID"] + ')">delete</a></td></tr>');
}

打开对话框的功能:

function updateform(id, rTeam, sTeam) {
    $('#id').val(id);
    $('#iID').val(id);
    $('#sTeam').val(rTeam);
    $('#vTeam').val(sTeam);
    updatedialog.dialog("open");
}

正在打开的对话框:

<div id="dialog-form" title="Update Dialog">
    <form>
        <fieldset>
            <label for="iID">Match ID</label>
            <input type="text" name="iID" id="iID" value="" class="text ui-widget-content ui-corner-all" />
            <label for="rTeam">Standardized Name</label>
            <input type="text" name="sTeam" id="sTeam" value="" class="text ui-widget-content ui-corner-all">
            <label for="sTeam">ID > Known Synonyms</label>
            <textarea rows="6" id="vTeam" class="form-control" style="min-width: 100%"></textarea>
            <input type="hidden" name="id" id="id" value="" />
            <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
        </fieldset>
    </form>
</div>

0 个答案:

没有答案