Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何处理'&'';(';,';)';在javascript中_Javascript_Asp.net - Fatal编程技术网

如何处理'&'';(';,';)';在javascript中

如何处理'&'';(';,';)';在javascript中,javascript,asp.net,Javascript,Asp.net,从我的代码后面,我将把它传递给客户端脚本 C#代码隐藏 *请注意,如果我对下面的行进行注释,则不会出现js错误* 错误消息: 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:

从我的代码后面,我将把它传递给客户端脚本

C#代码隐藏 *请注意,如果我对下面的行进行注释,则不会出现js错误*

错误消息:

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

很难从您的问题中分辨出来,但听起来返回的值似乎包含单引号字符(撇号),它将在生成的javascript中结束字符串

为抛出错误的行生成的代码是什么

当类似的事情发生在我身上时,结果是:

return DeleteRow('1', '2', 'abscde', 'Mc'Adams');

这会因为Mc'Adams的值而导致错误。如果是这种情况,那么您必须通过一种方法发送数据,该方法将转义那些会损坏您的javascript的值。

从您的问题很难判断,但听起来返回的值似乎包含单引号字符(撇号)这将在生成的javascript中结束字符串

为抛出错误的行生成的代码是什么

当类似的事情发生在我身上时,结果是:

return DeleteRow('1', '2', 'abscde', 'Mc'Adams');

这会因为Mc'Adams的值而导致错误。如果是这种情况,那么您必须通过一种方法来发送数据,该方法将转义那些会损坏javascript的值。

您使用了单引号和双引号。在这里换行

var result = confirm('Are you sure you want to delete this record? \n\n Id: ' + Id + '\n Name: ' + Name)

您使用了混合单引号和双引号。在这里换行

var result = confirm('Are you sure you want to delete this record? \n\n Id: ' + Id + '\n Name: ' + Name)

以下是我如何阿贝尔修复它:

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().Trim().Replace("'", "\\'")));

以下是我如何阿贝尔修复它:

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().Trim().Replace("'", "\\'")));
是这个吗?是这个吗?