2013-08-23 103 views
0

我正在向表中動態添加行。對於其中一個單元格(cell8),我希望能夠單擊以rowIndex作爲參數值調用javascript函數(saveDeleteAction(rowIndex))。產生不產生rowIndex位置的實際值的HTML:Javascript轉義字符

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

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

你有問題嗎? –

回答

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