简体   繁体   English

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

[英]jQuery Popup not displaying string with square brackets inside

I have been stuck on this for awhile. 我已经坚持了一段时间。 I am not too sure where the problem is as it does not throw any errors. 我不太确定问题出在哪里,因为它不会引发任何错误。 This code works for most strings. 此代码适用于大多数字符串。 However, I noticed that the jQuery Popup function does not run whenever there is a special character in the string I want it to show. 但是,我注意到,只要要显示的字符串中有特殊字符,jQuery Popup函数就不会运行。 In this case it seems to not popup due to "[" and "]" in my string. 在这种情况下,由于我的字符串中没有“ [”和“]”,因此似乎没有弹出。 I tried replacing "[" and "]" with "(" and ")" but it still doesn't seem to work as intended. 我尝试将“ [”和“]”替换为“(”和“)”,但它似乎仍无法按预期工作。

Here is my example code: 这是我的示例代码:

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;

Here is my jQuery Popup Function on front-end with div. 这是我的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>

I've been trying all sorts of escape strings or and literal strings like @"Unilateral pulmonary emphysema [MacLeod's syndrome]" and replacing the square brackets with something else but it doesn't seem to work. 我一直在尝试各种转义字符串或文字字符串,例如@"Unilateral pulmonary emphysema [MacLeod's syndrome]"并用其他东西代替方括号,但似乎不起作用。 I'm not sure if its because of jQuery or C# that its not working because it's not throwing any error. 我不确定它是否由于jQuery或C#而不能工作,因为它没有引发任何错误。 It just seems to skip the popup whenever a square bracket appears in the string. 只要字符串中出现方括号,似乎就跳过弹出窗口。 Any help? 有什么帮助吗?

The problem is not the square brackets, the problem is the single quote ' in MacLeod's Syndrome which is terminating the argument to ShowPopup early. 问题不在于方括号,问题在于MacLeod's Syndrome的单引号' ,该引号尽早终止了ShowPopup的论点。 Escape that quote to fix the issue. 转义该引用以解决此问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM