How to ESCAPE "comma" in Javascript
EDIT1:
btnDelete.Attributes.Add("onclick", String.Format(@"return DeleteRow('{0}',{1},{2},{3});", e.Row.ClientID, e.Row.RowIndex, DataBinder.Eval(e.Row.DataItem, "Id"), "'" + DataBinder.Eval(e.Ro开发者_JAVA百科w.DataItem, "Name") + "'"));
edit:
i get this error:
Message: Unterminated string constant
i am passing the value from code behind and some of my text have somethinh lke this:
Foo3, In.c
//javascript
function DeleteRow(rowId, rowIdx, Id, Name) {
var textForMessage = "return confirm('Are you sure you want to delete this record with the name: \n{0} \n{1}');";
//removed code...
return result;
}
Do nothing. A comma has no special meaning inside a JavaScript string.
You don't need to escape the comma. You should surround the entire string with quotes:
'Foo3, In.c'
If this string is inside another string which is also single-quoted you may need to escape the quotes.
If the error is client side you can solve it by having:
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").ToString().Replace("'", "\'"));
If it's server side, please post the full error message plus stack trace.
\x2c
Useful in ajax.
function myfunction(id, str_URL) {
$.ajax({
type: "GET",
url: str_URL,
success: function(t) {
var link = "<a href=\x22JavaScript:MyJava(\x22Param1\x22\x2c\x22Param2\x22)\x22>Link text</a>";
}
});
}
\x22
is "
(quote)
Just reference the Hex column in the ascii table.
http://www.asciitable.com/index/asciifull.gif
If your trying to escape a throw error due to comas that you need in a non quoted could be string datatype. say you needed it that way post.example, + post.example,
var comma =",";
post.example.concat(comma) + post.example.concat(comma)
Using concat method will concatenate any variable type.
精彩评论