|
通过弹出式对话框,打开一个新窗口,经过一番操作后将值返回来,研究了半天,终于搞出一个实例来,供大家分享^_^
测试例子公有两个文件:test1.html、test2.html

1:test1.html文件的内容为:
<script> function btnclick() { var a = window.showModalDialog("test2.htm") var getvalue =""; for(i=0;i<a.length;i++) { getvalue +=a[i] + ","; } var oProName = document.getElementById("t1"); var oProName1 = document.getElementById("t2"); var stringArray = getvalue.split('&&');
var list = stringArray[0]; var list1 = stringArray[1]; var splitArray1 = list.split(/[,]/g); var splitArray2 = list1.split(/[,]/g); var text1 = ""; var text2 = ""; for(j=1;j<=splitArray1.length;j++) { text1 += splitArray1[j-1]; if(j<splitArray1.length) { text1 += " "; } } for(j=1;j<=splitArray2.length;j++) { text2 += splitArray2[j-1]; if(j<splitArray2.length) { text2 += " "; } } oProName.value = text1; oProName1.value = text2; } </script>
<input type = 'text' name = 't1' id = 't1' value =''/> <input type = 'text' name = 't2' id = 't2' value =''/> <input type = 'button' name = 'b1' id = 'b1' value ="GetValue" onclick="btnclick()"/>
2:text2.html的内容为:
<script> function sendTo(count) { var a=new Array(count); for(i=1;i<=a.length;i++) { a[i-1] = i; } a.length = 2*count + 1; for(i=count+1;i<=2*count;i++) { a[i]=i; } a[count] = '&&'; window.returnValue =a; window.close(); } </script> <body> <form> <input value="返回" type=button onclick="sendTo(5)"> </form>
大家看看就知道了。
为什么要使用showModalDialog的原因为:通过showModalDialog调用的新窗口未关闭,不能操作父窗口。
注意:我为什么要在text2.html测试文件中生成的字符串中要加一个"&"符号:是因为通过showModalDialog传递参数时只能获得一个参数,要想得到多个参数,我就想了这个办法,传过来后,我通过split或正则表达式来分开得到多个参数,希望对大家有帮助^_^
|