string.format
如果要格式的字符串里有"{}"时,函数会把{}看作是参数.
特别是用string.format编写脚本的时候.则就会有希望.
在做审核时如现了此情况.
源代码是如下:
string script = string.Format(@"
<script language='javascript'>
function OpenUpdate()
{
top.returnValue = 'true';
var arr = new Array();
arr[0] = '{0:d}';
arr[1] = '{1:d}';
var result = window.showModalDialog(""CustomerSetUser.aspx"", arr , ""status:no;help:no;resizable:no;scroll:no;dialogHeight:250px;dialogWidth:500px;"");
if (result != null)
{
location.href = location.href;
}
top.close();
}
OpenUpdate();
</script>" , customerId , (int)DataModel.Customer.Parties.CustomerUserType.Manage); 
运行程序时.老是出现字符串格不正确.
有没有看出来.问题出现在哪里?
是编写函数的时候出现了"{ }" string.format当作参数.
作如下修改:
string script = string.Format(@"
<script language='javascript'>
function OpenUpdate()
{{
top.returnValue = 'true';
var arr = new Array();
arr[0] = '{0:d}';
arr[1] = '{1:d}';
var result = window.showModalDialog(""CustomerSetUser.aspx"", arr , ""status:no;help:no;resizable:no;scroll:no;dialogHeight:250px;dialogWidth:500px;"");
if (result != null)
{{
location.href = location.href;
}}
top.close();
}}
OpenUpdate();
</script>" , customerId , (int)DataModel.Customer.Parties.CustomerUserType.Manage);
运行成功.
浙公网安备 33010602011771号