Javascript逃脱角色

时间:2013-08-23 01:48:54

标签: javascript html

我正在动态地向表中添加行。对于其中一个单元格(cell8),我希望能够单击以使用rowIndex作为参数值调用javascript函数(saveDeleteAction(rowIndex))。生成的HTML不会产生rowIndex的实际值:

function addRowToTable(entity,rowIndex)
  {
    var table=document.getElementById("entity");
    var row=table.insertRow(-1);
    var cell8=row.insertCell(7);
    cell8.innerHTML= saveDeleteAction(rowIndex);  
  }

function saveDeleteAction(rowIndex) {
  return '<a href=\'javascript:testing(rowIndex)\'; class="btn btn-small btn-warning"><i class="btn-icon-only icon-ok"></i></a>      <a href="javascript:;" class="btn btn-small"><i class="btn-icon-only icon-remove"></i></a>';
}

function testing(rowIndex){
  alert(rowIndex);
}

HTML GENERATED

<a href="javascript:testing(rowIndex)" ;="" class="btn btn-small btn-warning"><i class="btn-icon-only icon-ok"></i></a>

1 个答案:

答案 0 :(得分:2)

试试这个:

function saveDeleteAction(rowIndex) {
    return '<a href="javascript:testing(' + rowIndex + ');" class="btn btn-small btn-warning"><i class="btn-icon-only icon-ok"></i></a>      <a href="javascript:;" class="btn btn-small"><i class="btn-icon-only icon-remove"></i></a>';
}