2013-06-02 45 views
0

此代碼我轉換爲每個需要的Javascript中的StringBuilder

http://jquerymsgbox.ibrahimkalyoncu.com/

大家好我寫了下面的代碼來顯示一個警告

public static string ShowAlertMessage(string pHeader, string pError, Page page) 
{ 
    //StringBuilder sb = new StringBuilder(); 
    StringBuilder strScript = new StringBuilder(); 

    strScript.Append("<script type='text/javascript' src='Scripts/jquery-1.4.1.js'>"); 
    strScript.Append("</script>"); 
    strScript.Append("<script type='text/javascript' src='Scripts/jquery.msgBox.js'>"); 
    strScript.Append("</script>"); 
    strScript.Append("<link href='Styles/msgBoxLight.css' rel='stylesheet' type='text/css'>"); 
    strScript.Append("</link>"); 
    strScript.Append("<script type='text/javascript'>"); 
    strScript.Append("function example()"); 
    strScript.Append("{"); 
    strScript.Append("$msgBox({"); 
    strScript.Append("title:" + pHeader + ""); 
    strScript.Append(","); 
    strScript.AppendLine("content:" + pError + ""); 
    strScript.Append("});"); 
    strScript.Append("}"); 
    strScript.Append("</script>"); 
    page.ClientScript.RegisterStartupScript(page.GetType(), "Script", strScript.ToString(), true); 
    return strScript.ToString(); 
} 

但是,這是不是給我的預期輸出可以幫助我一些我出錯的地方

這是生成的字符串生成器

<script type='text/javascript' src='Scripts/jquery-1.4.1.js'></script> 
<script type='text/javascript' src='Scripts/jquery.msgBox.js'></script> 
<link href='Styles/msgBoxLight.css' rel='stylesheet' type='text/css'></link> 
<script type='text/javascript'> 
function example() 
{ 
    $msgBox({title:Testing Code, 
    content:Hello 
}); 
} 
</script> 
+1

答案**什麼問題**?它給你什麼?什麼是預期的輸出? – SLaks

+0

爲什麼'append'和'toString'以大寫字母開頭? –

+0

提示:閱讀生成的Javascript,你會看到問題 – SLaks

回答

0

得到了與此

public static string ShowAlertMessage(string pHeader, string pError) 
{ 
StringBuilder strScript = new StringBuilder(); 
strScript.Append("<script type=\"text/javascript\" src=\"").Append("Scripts/jquery-1.4.1.js").Append("\"></script>"); 
strScript.Append("<script type=\"text/javascript\" src=\"").Append("Scripts/jquery.msgBox.js").Append("\"></script>"); 
strScript.Append("<link rel=\"stylesheet\" type=\"text/css\" href=\"").Append("Styles/msgBoxLight.css").Append("\" />"); 
strScript.Append("<script type=\"text/javascript\">"); 
strScript.Append("(function example()"); 
strScript.Append("{"); 
strScript.Append("$.msgBox({"); 
strScript.Append("title:'" + pHeader + "'"); 
strScript.Append(","); 
strScript.Append("content:'" + pError + "'"); 
strScript.Append("});"); 
strScript.Append("})();"); 
strScript.Append("</script>"); 
return strScript.ToString(); 
}