html 插入两个文本框,一个文本框一个按钮在HTML中的两个不同的页面

的问题看起来是您使用的getElementById但输入的元素没有一个ID(他们只有一个名字)。

我还建议附加一个onSubmit事件到窗体并从按钮中删除onClick事件。

编辑:仔细查看代码后,我看到有一些其他问题可能会妨碍操作。最值得注意的是你不能嵌套窗体标签。还有一些其他的CSS和验证问题。

下面是一些工作代码:

测试页

function SubmitForm(el) {

// Get the form element so that we can set the action later

var form = document.getElementById('theForm');

// Set the action for the form based on which button was clicked

if (el.id == "A")

form.action = "a.php";

if (el.id == "B")

form.action = "b.php";

// You dont need to submit the form. It's alreasdy happening, so there is no need for an explicit call.

}

Enter Text:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面就是一个简单的 C# HTML 评论页面的完整代码和详细解释: ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Comments : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // 在页面加载时执行的代码 } protected void btnSubmit_Click(object sender, EventArgs e) { // 当用户点击提交按钮时执行的代码 string name = txtName.Text; string comment = txtComment.Text; // 将评论插入数据库 // 这里需要你自己编写数据库插入代码 // 清空文本框 txtName.Text = ""; txtComment.Text = ""; // 刷新页面 Response.Redirect(Request.RawUrl); } } ``` 在这个代码,我们创建了一个名为 `Comments` 的 Web 页面,并在其上通过 C# 和 HTML 代码实现了一个简单的评论系统。下面是对代码的详细解释: 首先,我们引入了一些必要的命名空间: ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; ``` 接着,我们定义了一个名为 `Comments` 的类,并且继承了 `System.Web.UI.Page` 类。这是因为我们要创建一个 Web 页面,所以必须继承 `Page` 类。 ```csharp public partial class Comments : System.Web.UI.Page ``` 在 `Comments` 类,我们定义了两个事件处理函数:`Page_Load` 和 `btnSubmit_Click`。这两个函数分别在页面加载和用户点击提交按钮时被调用。 ```csharp protected void Page_Load(object sender, EventArgs e) { // 在页面加载时执行的代码 } protected void btnSubmit_Click(object sender, EventArgs e) { // 当用户点击提交按钮时执行的代码 } ``` 在 `Page_Load` 函数,我们可以添加一些在页面加载时需要执行的代码。例如,可以从数据库读取已有的评论列表,并展示在页面上。 在 `btnSubmit_Click` 函数,我们处理了用户提交评论的逻辑。首先,我们从页面上获取用户输入的姓名和评论内容: ```csharp string name = txtName.Text; string comment = txtComment.Text; ``` 接着,我们将获取到的评论内容插入到数据库。这里需要你自己编写数据库插入代码。 ```csharp // 将评论插入数据库 // 这里需要你自己编写数据库插入代码 ``` 然后,我们清空输入框的内容,并刷新页面,以展示最新的评论列表。 ```csharp // 清空文本框 txtName.Text = ""; txtComment.Text = ""; // 刷新页面 Response.Redirect(Request.RawUrl); ``` 最后,我们在 HTML 代码创建了一个简单的表单,以便用户输入评论。在表单,我们添加了两个文本框(用于输入姓名和评论内容),以及一个提交按钮。 ```html <form id="form1" runat="server"> <div> <label for="txtName">Name:</label> <input type="text" id="txtName" name="txtName" /> </div> <div> <label for="txtComment">Comment:</label> <textarea id="txtComment" name="txtComment"></textarea> </div> <div> <input type="submit" id="btnSubmit" name="btnSubmit" value="Submit" /> </div> </form> ``` 这就是一个简单的 C# HTML 评论页面的完整代码和详细解释。需要注意的是,我的代码只提供了一个大致的框架,具体的实现还需要根据你的需求进行相应的修改和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值