0

这让我很沮丧。我试过了

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtDrugList.Focus();

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtDrugList.Text.Length > 0)
        {
            drugDiv.InnerHtml += txtDrugList.Text + " ";
            Response.Write("\n");

        }
        txtDrugList.Text = "";

    }
}

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtDrugList.Focus();

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtDrugList.Text.Length > 0)
        {
            drugDiv.InnerHtml += txtDrugList.Text + Environment.NewLine;


        }
        txtDrugList.Text = "";

    }
}

也不工作。我想要一个按钮单击将换行符添加到 div。为什么这不起作用?

4

1 回答 1

4

您还没有说出“都不工作”的意思 - 但是您是否还记得在 HTML 中您需要类似于<br />可见换行符的东西?

我强烈怀疑,如果您查看原始 HTML,您包含换行符 - 只是它没有对显示的版本做任何事情。所以我怀疑你想要类似的东西:

if (txtDrugList.Text.Length > 0)
{
    drugDiv.InnerHtml += "<br />" + txtDrugList.Text;
}

请注意,我之前也放置了换行符- txtDrugList.Text否则您在 HTML 的末尾有一个换行符,这可能不是您想要的。

于 2013-05-24T01:43:45.683 回答