從我的代碼後面我傳遞這對客戶端腳本如何在JavaScript
C#代碼背後 * 注:如果我的評論下面對付「&」,「(」,「)」線比我沒有得到js錯誤。 *
if (btnDelete != null)
{
btnDelete.Attributes["onclick"] = String.Format("return DeleteRow('{0}', '{1}', '{2}', '{3}');", e.Row.ClientID, e.Row.RowIndex, DataBinder.Eval(e.Row.DataItem, "Id"), DataBinder.Eval(e.Row.DataItem, "Name"));
}
//javascript
function DeleteRow(rowId, rowIdx, Id, Name) {
var result = confirm('Are you sure you want to delete this record? \n\n Id: ' + Id + "\n Name: " + Name);
if (!result)
HighlightRow(rowId, rowIdx % 2 ? "#DEEEE9" : "#FFFFFF");
return result;
}
錯誤消息:
Message: Unterminated string constant
Line: 1280
Char: 180
Code: 0
URI: http://localhost:4964/admin/default.aspx
Message: Unterminated string constant
Line: 1341
Char: 178
Code: 0
URI: http://localhost:4964/default.aspx
Message: Expected ')'
Line: 1401
Char: 152
Code: 0
URI: http://localhost:4964/default.aspx
難道這就是[同樣的問題之前(http://stackoverflow.com/questions/4997634/how-to-escape-逗號在JavaScript的)? – user113716 2011-02-15 02:30:20