[英]jQuery Popup not displaying string with square brackets inside
我已经坚持了一段时间。 我不太确定问题出在哪里,因为它不会引发任何错误。 此代码适用于大多数字符串。 但是,我注意到,只要要显示的字符串中有特殊字符,jQuery Popup函数就不会运行。 在这种情况下,由于我的字符串中没有“ [”和“]”,因此似乎没有弹出。 我尝试将“ [”和“]”替换为“(”和“)”,但它似乎仍无法按预期工作。
这是我的示例代码:
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;
这是我的div前端的jQuery Popup Function。
<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>
我一直在尝试各种转义字符串或文字字符串,例如@"Unilateral pulmonary emphysema [MacLeod's syndrome]"
并用其他东西代替方括号,但似乎不起作用。 我不确定它是否由于jQuery或C#而不能工作,因为它没有引发任何错误。 只要字符串中出现方括号,似乎就跳过弹出窗口。 有什么帮助吗?
问题不在于方括号,问题在于MacLeod's Syndrome
的单引号'
,该引号尽早终止了ShowPopup
的论点。 转义该引用以解决此问题。
codeDescription = dt.Rows[0][0].ToString().Trim().Replace("'", @"\'");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.