单击复选框时如何选择和取消选择列表框中的所有项目 [英] how to select and deselect all items in listbox when click checkbox

查看:81
本文介绍了单击复选框时如何选择和取消选择列表框中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码在单击复选框时选择了列表框中的所有项目.

在page_load

I used this code for select all items in listbox when click the checkbox.

in page_load

listbox1.Attributes.Add("onclick", "javascript: selectall();")



在javascript中:



in javascript:

function selectall()
     {
     //var sel=document.getElementById('cb_selall');
     for(i=0; i<document.form1.li_mana_cards.options.length; i++)
     {
       document.form1.li_mana_cards.options[i].selected = true;
     }
     }


在OP中:
我想在单击复选框时取消选择列表框中的所有项目.我不知道如何为该过程编写代码.如果您知道请帮助我."


From the OP:
"I want to deselect all items in listbox when i click checkbox. I dont know how to write code for this process. If u know plz help me."

推荐答案

如果您提供的用于选择项目的代码有效,为什么不进行更改:将其重命名为"deselectall",并将"true"替换为"false" ...
If the code you have given for selecting the items is working, why not change it: Rename it to "deselectall" and replace "true" with "false"...


http://forums.asp.net/t/1138169.aspx/1 [ ^ ]

希望以上信息对您有所帮助.
http://forums.asp.net/t/1138169.aspx/1[^]

I hope the above information will be helpful.


我编写了此代码,以在单击复选框时选择和取消选择列表框中的所有项目.它运作良好.感谢所有人.

Javascript:

I wrote this coding to select and deselect all items in listbox when click checkbox. Its working well. Thanks to all.

Javascript:

function selectall(cb_selall)
     {

     if (cb_selall.checked)
       {

         for(i=0; i<document.form1.li_mana_cards.options.length; i++)
            {
               document.form1.li_mana_cards.options[i].selected = true;
            }
            }
     else
     {

     for(i=0; i<document.form1.li_mana_cards.options.length; i++)
            {
               document.form1.li_mana_cards.options[i].selected = false;
            }

      }

           }



页面加载:



Page Load:

cb_red_inac.Attributes.Add("onclick", "javascriptselectall(this);")


这篇关于单击复选框时如何选择和取消选择列表框中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆