asp.net代码练习 work008 <%%>和<%=%>的使用,输出九九乘法表

本文比较了两个ASP.NET页面WebForm1.aspx和WebForm2.aspx,展示了如何使用C#的不同语法编写前端代码,分别用`<%%>`和`<%=%>`表达式输出九九乘法表,揭示了ASP.NET中前端脚本的两种常见写法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

webform1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="work008.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>用Response输出九九乘法表</title>
    <!-- 前端页面如何使用< % % >编写脚本代码 -->
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table border="1" style="width:100%;">
            <tr>
                <th colspan="9">九九乘法表</th>
            </tr>
            <%
                for (int row = 1; row < 10; row++)
                {
                    Response.Write("<tr>");
                    for (int col = 1; col < 10; col++)
                    {
                        if (col <= row)
                        {
                            Response.Write(string.Format("<td>{0} * {1} = {2}</td>", col, row, col * row));
                        }
                        else
                        {
                            Response.Write("<td>&nbsp;</td>");
                        }
                    }
                    Response.Write("</tr>");
                }
                 %>
        </table>
    </div>
    </form>
</body>
</html>

webform2.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="work008.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>九九乘法表</title>
    <!--如何使用 < % = % >符号,来写前端代码,此种方式asp用的较多,类似php编写,但是说实话,在asp.net中
        没人会写如此晦涩难懂的程序,除非头不合适。-->
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table border="1" style="width:100%;">
            <tr>
                <th colspan="9">九九乘法表</th>
            </tr>
            <% for (int row = 1; row < 10; row++){ %> 
            <tr>
                <%
                    for (int col = 1; col < 10; col++)
                    { 
                        if(col <= row)
                        {
                %>
                <td><%=col %> * <%=row %> = <%=col*row %></td>
                <%
                        }
                        else
                        {
                %>
                <td><%= "&nbsp;" %></td>
                <%
                        }
                    }
                    
                    }     
                %>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虾米大王

有你的支持,我会更有动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值