110,534
社区成员
发帖
与我相关
我的任务
分享
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script>
function showid()
{
alert(event.srcElement.id+"点了!");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="b1" type="button" value="button" OnClick="showid()" />
<input id="b2" type="button" value="button" OnClick="showid()" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is Button)
{
c.Click += new EventHandler(c_Click);
}
}
}
void c_Click(object sender, EventArgs e)
{
this.textBox1.Text = ((Button)sender).Text;
}
}
}