簡體   English   中英

jQuery Popup不顯示內部帶有方括號的字符串

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM