关于showModalDialog传多值回父窗体实现

script1.html
 <script language="javascript" src="myobj.js"></script>
 <script language="javascript">
 function vilidate(obj){
  var boxs = document.getElementsByName("a");
  for(var i=0;i<boxs.length;i++){
   if(obj.checked){
    boxs[i].checked=true; 
   }else{
    boxs[i].checked=false; 
   }
  }
 }

 function xuanze(){
  var rV = new myobj(null,null);
  rv = window.showModalDialog("scriptMD.html",window,"dialogWidth=600px;dialogHeight=300px"); 
  if(rv!=null){
   document.getElementById("mc").value=rv.mcc;
   document.getElementById("ah").value=rv.ahh;
  }
 }
 
 </script>
 <form name="form1" action ="" method="post">
  <input type="checkbox" name="x" id="x" value="0" onclick="vilidate(this)">ppppp<br/>
  <br>
  <br>
   <input type="checkbox" name="a" value="1">a<br/>
   <input type="checkbox" name="a" value="2">b<br/>
   <input type="checkbox" name="a" value="3">c<br/>
   <input type="checkbox" name="a" value="4">d<br/>
   <input type="checkbox" name="a" value="5">e<br/>
   <input type="checkbox" name="a" value="6">f<br/>
   <input type="checkbox" name="a" value="7">g<br/>
   名称:<input type="text" name="mc" id="mc" size="20px" /><br/>
   爱好:<input type="text" name="ah" id="ah" size="20px" /><br/>
   <input type="button" name="xz" id="xz" value="选择名称和爱好" onclick="xuanze()"/>
  </form>

scriptMD.html
<script language="javascript" src="myobj.js"></script>
<script language="javascript">
 function check1(){
  var name = document.getElementById("mc");
  var boxs = document.getElementsByName("ah");
  var str = "";
  if(name.value.length<=0){
   alert("请输入名字!");
   name.focus();
   return;
  }
  var j=0;
  for(var i=0;i<boxs.length;i++){
   if(boxs[i].checked){
    str =str+","+boxs[i].value;
    j++;
   }
  }
  if(j==0){
   str="没有爱好!";
  }
  var mo = new myobj(name.value,str);
  window.returnValue=mo;
  window.close();
 }
 
</script>
  <form name="form2" method="post" action="">
 名称:<input type="text" name="mc" id="mc" size="20px"/><br>
 爱好:<input type="checkbox" name="ah" value="看书"/>看书<br>
    <input type="checkbox" name="ah" value="画画"/>画画<br>
    <input type="checkbox" name="ah" value="上网"/>上网<br>
    <input type="checkbox" name="ah" value="写字"/>写字<br>
    <input type="checkbox" name="ah" value="旅游"/>旅游<br>
    <input type="button" name="bt" value="...OK..." onclick="check1()"/>
  </form>

myobj.js

//myobj.js
function myobj(mcvalue,ahvalue){
 this.mcc = mcvalue;
 this.ahh = ahvalue;
}

你可能感兴趣的:(JavaScript,html,F#,J#,旅游)