对于WEB客户端开发而言,现在越来越多的使用JavaScript脚本来实现一些业务逻辑,即所谓的RIA应用,我们可以把JS文件理解成JSP文件的逻辑实现,JSP文件作为界面显示.以下是一些JS开发中常用的一些方法:
1.窗口调用
模态:window.showModalDialog();
非模态:window.showModelessDialog();window.open();
2.窗口调用时窗体间的参数传递
调用窗口传递参数
window.showModalDialog("目标URL",参数名,"其他特性");-- 参数可以是任何类型,
被调用窗口获得参数
window.dialogArguments;
3.窗口返回值
window.returnValue;
exp:
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script type="text/javascript">
- function openNewWeb() {
- var winValue = window.showModalDialog("WebForm1.aspx", null, "dialogHeight=200px,dialogWidth=200px,center=1");
- document.getElementById("result").innerText = winValue;
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <input id="Button1" type="button" value="button" onclick="openNewWeb()" />
- <div id="result">
- </div>
- </form>
- </body>
- </html>
返回值
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script type="text/javascript">
- function returnResult() {
- window.returnValue = document.getElementById("txtUserName").value;
- window.close();
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <input id="txtUserName" type="text" />
- <input id="btn" type="button" value="button34" onclick="returnResult()" />
- </form>
- </body>
- </html>