jQuery Popup不显示带方括号的字符串

时间:2015-10-27 21:07:24

标签: javascript c# jquery asp.net

我被困在这一段时间了。我不太确定问题出在哪里,因为它不会引发任何错误。此代码适用于大多数字符串。但是,我注意到只要我想要显示的字符串中有特殊字符,jQuery Popup函数就不会运行。在这种情况下,由于我的字符串中的“[”和“]”,它似乎没有弹出。我尝试将“[”和“]”替换为“(”和“)”,但它似乎仍无法正常工作。

这是我的示例代码:

PATH

这是我在前端的jQuery Popup Function with div。

string test = tbICD91.Text; //<--"J43.0"
string codeDescription = string.Empty;
codeDescription = dt.Rows[0][0].ToString().Trim(); //<--"Unilateral pulmonary emphysema [MacLeod's syndrome]"
if (String.IsNullOrEmpty(codeDescription))
{
    ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('Cannot find description to code in textbox');", true);
    ScriptManager.RegisterStartupScript(Page, this.GetType(), "ScrollPage", "ResetScrollPosition();", true);
}
else
{
    ClientScript.RegisterStartupScript(this.GetType(), "Popup", string.Format("ShowPopup('{0}: {1} ');", test, codeDescription), true);
    ScriptManager.RegisterStartupScript(Page, this.GetType(), "ScrollPage", "ResetScrollPosition();", true);
}
return;

我一直在尝试各种各样的转义字符串或文字字符串,如<script type="text/javascript"> function ShowPopup(message) { $(function () { $("#dialog").html(message); $("#dialog").dialog({ title: "ICD Code Description", buttons: { Close: function () { $(this).dialog('close'); } }, modal: true }); }); }; </script> <div id="dialog" style="display: none"></div> ,并用其他东西替换方括号,但它似乎不起作用。我不确定它是否因为jQuery或C#而无效,因为它没有抛出任何错误。只要字符串中出现方括号,它似乎就会跳过弹出窗口。有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

问题不在于方括号,问题是'中的单引号MacLeod's Syndrome,它提前终止了ShowPopup的参数。逃避报价以解决问题。

codeDescription = dt.Rows[0][0].ToString().Trim().Replace("'", @"\'");