我想通过拼写html语句来在显示一个浮层出来。浮层显示是通过js控制的,
protected string getDivHtml(string JobID)
        {            string s;
            DataTable dt = dalIntership.GetIntershipInfobyJobid(JobID);
            s = "<table id=" + "DivTipShowDuty" + "width=" + "100%" + "border=" + "1px" + "bordercolor=" + "#FF0000" + ">";
            s += "<tr><td bgcolor=" + "#F1F1F1" + "><b>工作职责:</b></td><td width=" + "200" + " style=" + "background-color:#ffffff;table-layout:fixed;height:30" + ">" + dt.Rows[0]["Duty"] + "</td></tr>";
            s += "<tr><td height=" + "1" + "></td></tr>";
            s += "<tr><td bgcolor=" + "#F1F1F1" + "><b>实习资格:</b></td><td width=" + "200" + " style=" + "background-color:#ffffff;table-layout:fixed;" + ">" + dt.Rows[0]["JobRequest"] + "</td></tr>";
            s += "</table>";
            return s;
        }不知道这里面为什么不能有'这字符出现???

解决方案 »

  1.   

    字符串拼接要用StringBuilder,还有拼接的时候要注意,很容易出错
      

  2.   

    为什么有些字符串可以写成一个的你也用""+""来拼接,比如第一句你可以写成这样:
    s = "<table id='DivTipShowDuty' width='100%' border='1px' bordercolor='#FF0000'>";
      

  3.   

    实验了一下,没有发现有问题<table id=DivTipShowDutywidth=100%border=1pxbordercolor=#FF0000>
    <tr><td bgcolor=#F1F1F1><b>工作职责:</b></td><td width=200 style=background-color:#ffffff;table-layout:fixed;height:30>'1'23</td></tr>
            <tr><td height=1></td></tr>
            <tr><td bgcolor=#F1F1F1><b>实习资格:</b></td><td width=200 style=background-color:#ffffff;table-layout:fixed;>4'56'</td></tr>
        </table>
      

  4.   

    使用StringBuilder,\"
    单步跟踪