window.returnValue和window.showModalDialog

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	<[重点理解模式窗口的概念]>
	
	window.returnValue的用法:
	return value 是javascript中html 的windows 对象的属性,目的是返回窗口值,当用
	window.showModalDialog 函数打开一个IE的模式窗口,模式窗口: 打开后不能操作父
	窗口,只能等模式窗口关闭时候才能操作,用于返回窗口的值<存在的最大价值>:
	一个典型的应用场景是: 在父窗口打开一个小窗口, 小窗口用ztree 树形jsp页面,然后
	点击树的一个节点, 得到节点的key和value, 父窗口得到key 和value 进行后台操作
	 -->
	 <script type="text/javascript">
	  function showmodal()
	   {
	      var dialogSettings= "dialogWidth:350px;dialogHeight:350px;help:no;status:no" ;
	      var ret = window.showModalDialog("child.jsp", true, dialogSettings);
	      
	      // 获取模式窗口的值,模式窗口的值通过window.returnValue 设置;
	      if (ret)
	      {
	         var returnval = ret.split(":");
	         var obj = new Object();
	         obj.key = returnval[0]; 
	         obj.value = returnval[1];
	         alert(obj.key + "=" + obj.value);
	      }
	      
	    }
	 </script>
  </head>
  
  <body>
    <input id="button" type="button" value="button"  οnclick="javascript:showmodal();">
  </body>
</html>

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <script type="text/javascript">
        // 注意赋值之后,要调用window.close关闭小窗口,回到父窗口进行后续操作
       function trans(tag)
       {   
           window.returnValue = tag;
           window.close();
         //window.returnValue = tag == 0? false :true;
         //window.close();
        } 
    </script>
  </head>
  
  <body>
    <input id="button"  type=button  value="returnValueToItsParent" οnclick="javascript:trans('sin(30):0.5');">
    <!-- 
    <input id="button"  type=button  value=" '返回真' " name=button1 οnclick="trans(1)">
    <input id="button2" type=button  value=" '返回假' " name=button2 οnclick="trans(0)">
     -->
  </body>
</html>

 

webAPI

event.srcElement

------------------------------------------------------------------------------------------------------------  
杂碎:<[不相干的东西]>

// <[::也可以直接在模式窗口返回一个对象,可以在父窗口得到模式窗口的对象及对象的属性值::]>
function nodeClicked(nodeID)
{
	  var clickNode = dyntree.getNodeFromMap(nodeID);
	  var result = new Object();
	  result.id = nodeID;
	  result.name = clickNode.title;
	  result.value = clickNode.target;
	      
	  if (clickNode.isLeaf())
	  {
	    window.returnValue = result;
	    window.close();
	  }
	  else
	  {
	    alert("请选择相应的叶子节点!");
	  }
}

// <[::当点击模式窗口树形节点时,直接给父窗口相关的DOM对象赋值::]>
function chooseCartShoppingItem(lable,price)
{
    var obj = new Date();
	var action = "${request.contextPath}/yourPackageName/yourHandleAction.action";
	var spec = "scroll:yes;center:yes;resizable:yes;status:no;help:no;dialogWidth:300px;dialogHeight:400px";
	
	var result = window.showModalDialog(action, '', spec);
	if (result)
	{
	    document.getElementById(price).value = result.value;
	    document.getElementById(lable).value = result.name;
	}
};

// javascript 对象模型
var a = new Object(); a.attribute1 = ""; a.attribute2 = []; a.attribute3 = {};
window.returnValue = a;   
var b = window.returnValue;
b.attribute1;
b.attribute2;
b.attribute3;

var url = " ";
<if test="${(fn:substring(cartShop.itemId,0,6) == '001001')}"></if>
window.parent.document.getElementById("toolBarFrame").src = url;

<[https://developer.mozilla.org/en-US/docs/Web/API]> -> Web API Interfaces 

// <[ Dom对象的getElementsByTagName 方法]>
// Element.getElementsByTagName is similar to Document.getElementsByTagName(), 
// except that its search is restricted to those elements which are descendants of the specified element.
// Syntax
// elements = element.getElementsByTagName(tagName)
// Example
// check the alignment on a number of cells in a table. 

var table = document.getElementById("forecast-table"); 
var cells = table.getElementsByTagName("td"); 
for (var i = 0; i < cells.length; i++) 
{ 
    var status = cells[i].getAttribute("data-status"); 
    if ( status == "open" ) { 
        // grab the data 
    }
}

function f_qingyuan_selectProduct()
{
    var tab = document.getElementById("productTab");
    // <[ think about: <Element>var tab = document.getElementById("productTab");]>
    var trs = tab.getElementsByTagName("tr");
    if(trs.length <= 1)
    {
        alert("请选择一项内容");
        return false;
    }
	
	var deleteBtn = document.getElementsByName("deleteComplainProblemBtn");
	if (deleteBtn != undefined || deleteBtn != null)
	{
	  	if (deleteBtn.length == 0)
	  	{
	  	alert("“投诉问题定位分析信息”不允许为空!");
	  	return false;
	  	}
          }
              return true;
}

//  <[从Table对象中移除一行数据 ]>
function deleteTableRow()
{
    var oTable = document.getElementById("productTab");
    var deleteBtn = document.getElementsByName("btnDe");
    var srcIndex = getSpIndex(deleteBtn);
    if(confirm("确定要删除该问题投诉类型吗?"))
    {
       oTable.deleteRow(srcIndex + 1); 
    }
	
    // 只是从表格移除了一行,要对该行的数据在数据库完成操作
     dataOperation();
}

// 参考博文: <[ http://lflianglan.blog.51cto.com/7020643/1346733]>
// 因为系统规定了用IE作为固定的浏览器,这里可以直接使用event.srcElement而不用去校验;
function getSpIndex(indexList)
{
    var srcIndex = -1;
    for (var i = 0; i < indexList.length; i++)
    {
        if (indexList[i] == event.srcElement)
        {
            srcIndex = i;
            break;
        }
    }
    return srcIndex;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值