<div style="background-color:#E8E8E8;height:100px;border:1px black solid;" > 
显示的文本:  <input type="text" id="txtTextField" > <br > 
文本对应的值:  <input type="text" id="txtValueField" > 
<br > 
<input type="button" id="submit" value="提交" onclick="setValue()" > 
</div > 
这段话我会改成差不多:<div style="background-color:#E8E8E8;height:100px;border:1px black solid;" > 
<input type="checkbox" id="txtTextField1" > aa<br > 
 <input type="checkbox" id="txtTextField2" >bb <br > 
<input type="checkbox" id="txtTextField3" >bb <br > 
<input type="button" id="submit" value="提交" onclick="setValue()" > 
</div > 
请教js部分该怎么改,没怎么学习js,自己加了一个for循环,老出错,高手指教!谢谢啥

解决方案 »

  1.   

    第一张页面:
    JS:添加这个函数(注意函数名,我已改过)function addItems()
    {
       var items=window.showModalDialog("addItems.aspx","arg","dialogWidth:550px;dialogHeight:200px;");
       if(items!=null && items.length!=0)
       {
          var oSelect=$("selTest");
          for(var i=0;i<items[0].length;i++)
          {
             var newItem=new Option(items[0][i],items[1][i]);
             oSelect.options[oSelect.options.length]=newItem;
          }
       }
    }在HTML里修改部分代码:(注意红色部分)<div style="background-color:#E8E8E8;height:100px;border:1px black solid;">
    <select id="selTest">
    <option value="">--请选择--</option>
    </select>
    <input type="text" id="myText">
    <input type="button" id="addItem" value="添加项目" onclick="addItems()">
    <input type="button" id="delItem" value="删除选中的项目" onclick="delItem()">
    </div>第二张页面:
    JS:function setValue()
    {
       //debugger
       var arrItem=new Array();
       var arrTextField=new Array();
       var arrValueField=new Array();
       var oCheckBoxes=document.all.tags("input");
       for(var i=0;i<oCheckBoxes.length;i++)
       {
          var oCheckBox=oCheckBoxes[i];
          var isCheckBox=oCheckBox.type=="checkbox" && oCheckBox.checked;
          if(isCheckBox)
          {
             arrTextField.push(oCheckBox.value);
             arrValueField.push(oCheckBox.nextSibling.innerText);
          }
       }
       arrItem.push(arrTextField);
       arrItem.push(arrValueField);
       window.returnValue=arrItem;
       window.close();
    }HTML:<div style="background-color:#E8E8E8;height:100px;border:1px black solid;font-size:12px">
    <br>
    <p>请勾选要添加的项目</p>
    <br>
    <p>
    <input type="checkbox" id="chk1" value="苹果"><label for="chk1">我是苹果</label> 
    <input type="checkbox" id="chk2" value="香蕉"><label for="chk2">我是香蕉</label>
    <input type="checkbox" id="chk3" value="芒果"><label for="chk3">我是芒果</label> 
    <input type="checkbox" id="chk4" value="橘子"><label for="chk4">我是橘子</label>
    <input type="checkbox" id="chk5" value="菠萝"><label for="chk5">我是菠萝</label> 
    <input type="checkbox" id="chk6" value="葡萄"><label for="chk6">我是葡萄</label>
    <input type="checkbox" id="chk7" value="橙子"><label for="chk7">我是橙子</label>
    </p>
    <p align="center"><input type="button" value="提交" onclick="setValue()"></p>
    </div>===============================
    可以了.
      

  2.   

    看一下,DHTML里,对于对象有一个remove方法.可以删除列表框里的内容。 
      

  3.   

    万分感激HonorsOffice 兄,多日的困扰终于解决了,谢谢
      

  4.   

    remove好像有点问题,不知道该怎么修改下