我已经被这个问题困扰了一段时间了。我不太确定问题出在哪里,因为它不会引发任何错误。此代码适用于大多数字符串。但是,我注意到只要我希望它显示的字符串中有特殊字符,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 弹出函数。
<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# 而无法工作,因为它没有抛出任何错误。每当字符串中出现方括号时,它似乎都会跳过弹出窗口。有什么帮助吗?
最佳答案
问题不在于方括号,问题在于 MacLeod's Syndrome
中的单引号 '
,它提前终止了 ShowPopup
的参数。转义该引用以解决问题。
codeDescription = dt.Rows[0][0].ToString().Trim().Replace("'", @"\'");
关于javascript - jQuery 弹出窗口不显示内部带有方括号的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33378480/