有一个CheckBoxList扣一个ListBox,CheckBoxList选了后要在ListBox中立刻列出,我在服务器完成的每都刷屏,能不能不刷屏实现啊

解决方案 »

  1.   

    在你的aspx中
    <script>
    function setList()
    {
    var table=document.getElementById("你的CheckBoxListID");
    var list=document.getElementById("你的ListBoxID");
    for(i=list.length-1;i>=0;i--)
    {
    list.options[i]=null;
    }
    var curOpt;
    for(i=0;i<table.rows.length;i++)
    {
    curOpt=table.rows[i].cells[0];
    if(curOpt.firstChild.checked)
    list.options[list.length]=new Option(curOpt.innerText);
    }
    }
    </script>
    在aspx.cs中
    你的CheckBoxListID.Attributes.Add("onclick","setList();");
      

  2.   

    <input type="checkbox" value="2" onclick="Sel(this.value)">
    <select name="sel" id="sel">
    <option value="1">1</option>
    <option value="2">2</option>
    </select>
    <script >
    function Sel(val){
    for (var i = 0; i < document.all.sel.length; i++){
    if (document.all.sel.options[i].value == val){
    document.all.sel.options[i].selected = true; }
    }
    }
      

  3.   

    to powbcom(一搏云天):谢谢,不过我的CheckBoxList是在服务器上绑定的数据,你的方法我有试过没用 to welshem(天堂客),你的方法通过了,谢谢
    上面的50分给你了不过另有问题,另加30分请问:我按了确定钮后,回来的页面里ListBox空了,怎么改才能有值
      

  4.   

    好办啊,在body 中加onload="setList()"