如何给checkboxlist控件中的checkbox添加js onclick事件

yuemb369 2007-04-06 01:17:27
如题,先谢谢各位大虾
...全文
1642 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuemb369 2007-05-24
  • 打赏
  • 举报
回复
回复人:ltmltm123456() () 信誉:100 2007-4-24 22:07:58 删除

我来 得你那个分
你那个 checkbox 控件该为..html的checkbox空间 才会有onclick事件 .....
给分给我........不然不说了 哈哈


这种人太可恶
yuemb369 2007-05-24
  • 打赏
  • 举报
回复
我用就是用checkboxlist,跟html的checkbox空间没什么关系,如果不能 实现的话就是不能实现。
yuemb369 2007-04-24
  • 打赏
  • 举报
回复
各位看到帖的自己尝试一下吧,我之前就尝试过各位给的方法,没能解决问题才上来提问
yuemb369 2007-04-24
  • 打赏
  • 举报
回复
mzwww(努力的奴隶)给的方法不对,ListItem 到CheckBox 根本就无法转换
ltmltm123456 2007-04-24
  • 打赏
  • 举报
回复
我来 得你那个分
你那个 checkbox 控件该为..html的checkbox空间 才会有onclick事件 .....
给分给我........不然不说了 哈哈
ychangh 2007-04-24
  • 打赏
  • 举报
回复
for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
{
this.CheckBoxList1.Items[i].Attributes.Add("onclick", "alert('1')");
}
shaohaiou 2007-04-24
  • 打赏
  • 举报
回复
稍微测试一下就能出来了....
shaohaiou 2007-04-24
  • 打赏
  • 举报
回复
foreach (ListItem li in CheckBoxList1.Items)
{
li.Attributes.Add("onclick", "alert(1)");
}
mzwww 2007-04-20
  • 打赏
  • 举报
回复

foreach (ListItem li in CheckBoxList1.Items)
{
System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)li
cb.Attributes["onclick"] = "aa()"
}
yuemb369 2007-04-20
  • 打赏
  • 举报
回复
事实证明各位给的方法都不对,各位都太想当然了,自己没有实际测试过就以为是对的
shaohaiou 2007-04-11
  • 打赏
  • 举报
回复
在DataBound事件里写上
foreach (ListItem li in CheckBoxList1.Items)
{
System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)li
cb.Attributes.Add("onclick", "aa();");
}
jxsddboy22 2007-04-11
  • 打赏
  • 举报
回复
foreach (ListItem li in CheckBoxList1.Items)
{
li.Attributes.Add("onclick", "aa();");
}
yuemb369 2007-04-11
  • 打赏
  • 举报
回复
up
yuemb369 2007-04-06
  • 打赏
  • 举报
回复
up
yuemb369 2007-04-06
  • 打赏
  • 举报
回复
老兄,这样不行,你自己试试
king5281273 2007-04-06
  • 打赏
  • 举报
回复
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.CheckBoxList1.Attributes.Add("onclick","Test()");
}
// 在此处放置用户代码以初始化页面
}

<script language="javascript">
function Test()
{
alert("a");
}
</script>
在线考试系统 Sub submit_click(ByVal sender As Object, ByVal e As EventArgs) Dim grade As Integer '单选 If RadioButtonList1.SelectedIndex = "2" Then grade = grade + 10 Else a.Visible = True Image1.Visible = True End If If RadioButtonList2.SelectedIndex = "2" Then grade = grade + 10 Else b.Visible = True Image2.Visible = True End If If RadioButtonList3.SelectedIndex = "2" Then grade = grade + 10 Else c.Visible = True Image3.Visible = True End If If RadioButtonList4.SelectedIndex = "2" Then grade = grade + 10 Else d.Visible = True Image4.Visible = True End If If RadioButtonList5.SelectedIndex = "2" Then grade = grade + 10 Else f.Visible = True Image5.Visible = True End If '多选 If CheckBoxList1.Items(0).Selected = False And CheckBoxList1.Items(1).Selected = True And CheckBoxList1.Items(2).Selected = True And CheckBoxList1.Items(3).Selected = True Then grade = grade + 10 Else g.Visible = True Image6.Visible = True End If If CheckBoxList2.Items(0).Selected = False And CheckBoxList2.Items(1).Selected = False And CheckBoxList2.Items(2).Selected = True And CheckBoxList2.Items(3).Selected = False And CheckBoxList2.Items(4).Selected = True And CheckBoxList2.Items(5).Selected = True And CheckBoxList2.Items(6).Selected = True Then grade = grade + 10 Else h.Visible = True Image7.Visible = True End If If CheckBoxList3.Items(0).Selected = True And CheckBoxList3.Items(1).Selected = True And CheckBoxList3.Items(2).Selected = True And CheckBoxList3.Items(3).Selected = False Then grade = grade + 10 Else i.Visible = True Image8.Visible = True End If If CheckBoxList4.Items(0).Selected = True And CheckBoxList4.Items(1).Selected = True And CheckBoxList4.Items(2).Selected = False And CheckBoxList4.Items(3).Selected = True And CheckBoxList4.Items(4).Selected = True Then grade = grade + 10 Else j.Visible = True Image9.Visible = True End If If CheckBoxList5.Items(0).Selected = True And CheckBoxList5.Items(1).Selected = True And CheckBoxList5.Items(2).Selected = False And CheckBoxList5.Items(3).Selected = True Then grade = grade + 10 Else k.Visible = True Image10.Visible = True End If Dim objLabel As New Label objLabel.ID = "message" objLabel.Text = "您的得分为:" & grade & "分 !" '动态产生控件的应用样式的改变? 'objLabel.Style = "background-color:#ffffff;border-width:1;border-style:solid" Page.Controls.Add(objLabel) If grade = 100 Then MsgBox("哦啊!您真了不起,得了满分耶!", 1, "恭喜( ^_^ )") End If submit.Enabled = False reset.Enabled = False End Sub Sub reset_click(ByVal sender As Object, ByVal e As EventArgs) End Sub 在线考试 在线考试 一、单选(每小题十分,共50分) 1、 Do you have a preference _____ a particular food?      A.with B.at C.for D.in 正确答案为:C 2、 By now most freshmen have grown so used to university life that they have forgotten all those ______ about the university they originally had. A.concerns B.worry C.dreams D.ambition 正确答案为:C 3、 Many people want to buy it because,____ , the price is reasonable; ____ , it's rather durable.  A.on one side, on the other side B.for one thing, for another C.on the one hand, on the other hand D.in one part, in the other part 正确答案为:C 4、 The proposal ____ we start doing the experiment two days earlier has been agreed upon by all.  A.which B.what C.that D.of which 正确答案为:C 5、 ____ , we may look forward to better weather. A.comes B.has come C.to be coming D.having come 正确答案为:C 二、多选(每小题十分,共50分) 1.国三大国粹; 瓷器 国画 京剧 医 正确答案为:国画、京剧、医 2.四大民间传说: 窦娥冤 西厢记 牛郎织女 牡丹亭 梁山伯与祝英台 白蛇传 孟姜女 正确答案为:牛郎织女、梁山伯与祝英台、白蛇传、孟姜女 3. 建安七子有三曹: 曹操 曹丕 曹植 曹冲 正确答案为:曹操、曹丕、曹植 4.四大大名楼: 湖南岳阳岳阳楼 江西南昌滕王阁 山西永济鹳雀楼 湖北武汉黄鹤楼 云南昆明大观楼 正确答案为:湖南岳阳楼、江西滕王阁、湖北黄鹤楼、昆明大观楼 5.以下是古代名医的是: 扁鹊 张仲景 贾思勰 淳于意 正确答案为:扁鹊、张仲景、淳于意                 
删除之类操作需要全选功能,方便选择 public class MainActivity extends Activity { private ListView lv; private MyAdapter mAdapter; private ArrayList list; private Button bt_selectall; // private Button bt_cancel; // private Button bt_deselectall; private int checkNum; // 记录选的条目数量 private TextView tv_show;// 用于显示选的条目数量 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /* 实例化各个控件 */ lv = (ListView) findViewById(R.id.lv); bt_selectall = (Button) findViewById(R.id.bt_selectall); // bt_cancel = (Button) findViewById(R.id.bt_cancelselectall); // bt_deselectall = (Button) findViewById(R.id.bt_deselectall); tv_show = (TextView) findViewById(R.id.tv); list = new ArrayList(); // 为Adapter准备数据 initDate(); // 实例化自定义的MyAdapter mAdapter = new MyAdapter(list, this); // 绑定Adapter lv.setAdapter(mAdapter); // 全选按钮的回调接口 bt_selectall.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 遍历list的长度,将MyAdapter的map值全部设为true for (int i = 0; i < list.size(); i++) { MyAdapter.getIsSelected().put(i, true); } // 数量设为list的长度 checkNum = list.size(); // 刷新listview和TextView的显示 dataChanged(); } }); // 反选按钮的回调接口 // bt_cancel.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // // 遍历list的长度,将已选的设为未选,未选的设为已选 // for (int i = 0; i < list.siz

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧