简体   繁体   中英

Javascript Escape Character

I am dynamically adding rows to a table. For one of the cells(cell8), I want to be able to click to call a javascript function (saveDeleteAction(rowIndex)) with the rowIndex as the parameter value. The HTML generated does not produce the actual value of 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>

Try this:

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>';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM