描述:在HTML文件中用某个符号字符串去表示一个标签,在ashx代码中即可用变量名去代替这个标签名
html文件:
<table border="1" cellpadding="0" cellspacing="0"> <tr> <td style="color:Red">姓名</td> <td onclick="alert(‘@name你好‘);">@name</td> </tr> <tr> <td>年龄</td> <td>@age</td> </tr> </table>
ashx文件:
context.Response.ContentType = "text/html"; string name = "张三"; int age = 20; string FileName = context.Server.MapPath("~/HTMLPage1.htm"); string Html1 = File.ReadAllText(FileName); string newHtml = Html1.Replace("@name",name).Replace("@age",age.ToString()); context.Response.Write(newHtml);
时间: 2024-12-15 22:23:03