`
康敏栋
  • 浏览: 168892 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

回答“QQ1145306946”提的问题“jsp 勾选数据添加到另一个页面”

 
阅读更多
解答http://www.iteye.com/problems/95288#s_200578的问题
以下是之前做过的,直接搬过来给你,你看看能不能去里面借鉴一下。下面的文件命名也是之前原班的
注意修改点:
1.本例中的“选择”按钮等同于你表单中的“增加”按钮
2.本例中在弹出页面勾选好了,点击“确定”按钮后,只将品名带出来了,而你的需求应该是把所有的都带出来吧,所以如果你想将其他字段的值也带出来你就在purchase.js中添加
3.本例不是很全,有可能不太看得懂,可以结合之前跟你说的图片看
[url]http://liangjie5305579-126-com.iteye.com/picture/125721 [/url]

1.PurchaseEdit.jsp(表单主页面)
注意:此处需要将purchase.js导入,并设置一个隐藏域selectgoods来接收你到时候所选物品id(第一二行)

<script type="text/javascript" src="../../js/purchase.js"></script>
<s:hidden id="selectgoods" name="selectgoods" />
<tr>
<TD width="100%" colspan="4" align="left" 
class="biaodan_ziduan_center">
<strong>物品清单</strong><input type="hidden" name="index" id="index1" />
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="table11">
<tr align="center">
	<td width="17%">
		品&nbsp;&nbsp;名
	</td>
	<td width="16%">
		需求数量
	</td>
	<td width="16%">
		实购数量
	</td>
	<td width="16%">
		金&nbsp;&nbsp;额
	</td>
	<td width="16%">
		单&nbsp;&nbsp;价
	</td>
	<s:if test='allPermission.indexOf("idselect")>0'>
	<td>
	<jtag:jbutton id="idselect" value="选择" editCondition="%{allPermission}" onclick="PurchaseGoodsSelect(table11)"
		cssClass="btn18 pbtn1" />&nbsp;
		
	</td>
	</s:if>
</tr>
<s:iterator value="b_v_flow_purchase_goods_list" id="b_v_flow_purchase_goods_list" status="index">
<tr>
	<td align="center" class="Tdcellright">
		<s:property value="%{b_v_flow_purchase_goods_list[#index.index].goodName}"/>
		<s:hidden id="goodid" name="%{'b_v_flow_purchase_goods_list['+#index.index+'].goodId'}"/>
		<s:hidden id="pgId" name="%{'b_v_flow_purchase_goods_list['+#index.index+'].pgId'}"/>
	</td>
	<td align="center" class="Tdcellright">
	<s:if test='flag==0'>
		<s:textfield name="%{'b_v_flow_purchase_goods_list['+#index.index+'].demandNum'}" theme="simple" 
		cssStyle="width:80%" cssClass="validate[required,onlyDouble]" id="demandNum%{#index.index}" />
	</s:if>
	<s:else>
	  <s:property value="%{b_v_flow_purchase_goods_list[#index.index].demandNum}"/>&nbsp;
	</s:else>
	<s:property value="%{b_v_flow_purchase_goods_list[#index.index].measurement}"/>
	</td>
	<td align="center" class="Tdcellright">
	<s:if test='flag==1'>
		<s:textfield name="%{'b_v_flow_purchase_goods_list['+#index.index+'].realNum'}"  id="realNum%{#index.index}"
		theme="simple" cssStyle="width:80%" cssClass="validate[required,onlyDouble]" onkeyup="getprice(%{#index.index})"/>
	</s:if>
	<s:else>
	  <s:property value="%{b_v_flow_purchase_goods_list[#index.index].realNum}"/>&nbsp;
	</s:else>
	<s:property value="%{b_v_flow_purchase_goods_list[#index.index].measurement}"/>
	</td>
	<td align="center" class="Tdcellright">
	<s:if test='flag==1'>
		<s:textfield name="%{'b_v_flow_purchase_goods_list['+#index.index+'].amount'}" id="amount%{#index.index}"
		theme="simple" cssStyle="width:80%" cssClass="validate[required,onlyDouble]" onkeyup="getprice(%{#index.index})"/>
	</s:if>
	<s:else>
	  &nbsp;&nbsp;¥<s:property value="%{b_v_flow_purchase_goods_list[#index.index].amount}"/>
	</s:else>
	</td>
	<td align="center" class="Tdcellright">
		<span id="price<s:property value="#index.index"/>">&nbsp;&nbsp;¥<s:property value="%{b_v_flow_purchase_goods_list[#index.index].goodPrice}"/>&nbsp;</span>
	</td>
	<s:if test='allPermission.indexOf("idselect")>0'>
	<td align="center" class="Tdcellright">
	<s:if test='flag!=2'>
<input type="button" name="Return"  value="删除" class="btn2 pbtn1" onClick="deleteResumeData(this,'table11','<s:property value="%{b_v_flow_purchase_goods_list[#index.index].pgId}"/>');" >&nbsp;
	</s:if>
	</td>
	</s:if>
</tr>
</s:iterator>
</table>
</TD>
</tr>


2.purchase.js
function PurchaseGoodsSelect(tableId) {
	//window.open("PurchaseGoodsSelectLoad.action");
	var result = window.showModalDialog("PuerchaseGoodsSelect.jsp",window,
			"dialogWidth:700px;dialogHeight:650px;scroll:yes;status:yes");
	if (result == 1) {
		var goods = document.getElementById("selectgoods").value;
		// alert(goods);
		if (goods != "") {
			var goodlist = goods.split(',');
			var goodinfo = "";
			for ( var i = 0; i < goodlist.length; i++) {
				// alert(goodlist[i]);
				if (goodlist[i] != "") {
					goodinfo = goodlist[i].split('@');
					addResumeRowLast(goodinfo[0], goodinfo[1],goodinfo[2], tableId)
				}
			}
		}
		// addResumeRowLast(tableId);
	}
}
function addResumeRowLast( goodid,goodsname,measurement, tableId) {
	var initTR = document.getElementById("table11").getElementsByTagName("tr");
	var posrow = initTR.length;

	addResumeRow(goodid,goodsname, measurement, tableId, posrow);
}

function addResumeRow( goodid,goodsname,measurement, tableId, rowindex) {// 物品
	// alert(goodid);
	var index = document.getElementById("index1"); 
    var flag=document.getElementById("flag").value;
   
	var newRow = tableId.insertRow(rowindex);

	var TR = document.getElementById("table11").getElementsByTagName("tr");

	newRow.align = "center";

	var newCell = newRow.insertCell();
	newCell.innerHTML = goodsname
			+ '<input type="hidden" name="b_v_flow_purchase_goods_list['
			+ index.value + '].goodId" value="' + goodid + '">';

	var newCell = newRow.insertCell();
	
	if(flag=="1"){
		newCell.innerHTML ='&nbsp;';
	}else{
		newCell.innerHTML = '<input type="text" id="demandNum'+index.value+'" name="b_v_flow_purchase_goods_list[' + index.value + '].demandNum"  '
        +'style="width:80%" class="validate[required,onlyDouble]">'+measurement;
	}
	var newCell = newRow.insertCell();
	if(flag=="1"){
	newCell.innerHTML = '<input type="text" name="b_v_flow_purchase_goods_list[' + index.value + '].realNum"  style="width:80%" class="validate[required,onlyDouble]" onkeyup="getprice('
		+ index.value + ')" id="realNum'+index.value+'">'+measurement;
	}else{
		newCell.innerHTML ='&nbsp;';
	}

	var newCell = newRow.insertCell();
	if(flag=="1"){
	newCell.innerHTML = '<input type="text" id="amount'+index.value+'" name="b_v_flow_purchase_goods_list[' + index.value + '].amount" '
	                    +' style="width:80%" class="validate[required,onlyDouble]" onkeyup="getprice('
	         			+ index.value + ')">';
	}else{
		newCell.innerHTML ='&nbsp;';
	}
	var newCell = newRow.insertCell();
	newCell.innerHTML = '<span id="price' + index.value + '">&nbsp;</span>';

	var newCell = newRow.insertCell();
	newCell.innerHTML = '<input type="button" name="Return" class="btn2 pbtn1" value="删除" onClick="deleteRows(\'index\',this,\'table11\');" ><input type="hidden" name="b_v_flow_purchase_goods_list[' + index.value + '].pgId" >&nbsp;'

	// if(rowindex>1)
	// {

	// TR[rowindex].getElementsByTagName("input")[0].value=TR[rowindex-1].getElementsByTagName("input")[1].value;
	// }

	index.value++;
}
function getprice(index) {

	//alert(index);
	var span = "price";
	var countstring = "realNum";
	var amountstring = "amount";
	var count = document.getElementById(countstring + index).value;
    //alert(count);
	var amount = document.getElementById(amountstring + index).value;
	var price = 0;
	if(IsNullToFloat(count)!=false){
	   price = IsNullToFloat(amount)/IsNullToFloat(count);
	   document.getElementById(span + index).innerHTML ='&nbsp;&nbsp;¥' +toDecimal2(price);
	}
}
function IsNullToInt(obj) {
	var re = 0;
	if (obj == null || obj == "" || isNaN(obj)||obj==0||obj=="0")
		return false;
	else {
		re = parseInt(obj);
	}
	return re;
}
function IsNullToFloat(obj) {
	var re = 0;
	if (obj == null || obj == "" || isNaN(obj))
		return false;
	else {
		re = parseFloat(obj);
	}
	return re;
}
//制保留2位小数,如:2,会在2后面补上00.即2.00
function toDecimal2(x) {
	var f = parseFloat(x);
	if (isNaN(f)) {
		return false;
	}
	var f = Math.round(x * 100) / 100;
	var s = f.toString();
	var rs = s.indexOf('.');
	if (rs < 0) {
		rs = s.length;
		s += '.';
	}
	while (s.length <= rs + 2) {
		s += '0';
	}
	return s;
}
function deleteResumeData(src, o, ID) {// 删除申购单物品信息
	if (confirm('确定要删除数据吗?')) {
		deleteRows('index', src, o);
		var url = 'DeletePurchaseGoodsById.action';
		var params = {
			checkedIds : ID
		};
		jQuery.post(url, params, callbackdelFun, 'json');
	}
}
function callbackdelFun(data) {
	alert("物品删除成功!");
}
// 删除行
function deleteRows(obj, src, o) {

	var index = document.getElementById(obj);
	var oRow = src.parentElement.parentElement;
	document.getElementById(o).deleteRow(oRow.rowIndex);

}

3.PuerchaseGoodsSelect.jsp(弹出来选择物品的页面)

此处把点击“确定”时的js代码复制出来
function updateData() {
               //此处三行代码表示获取已勾选的数据的id,再将id赋给selectgoods,也就是刚才页面的隐藏域的那个,此处你自己需改    
		var deleteFlags="deleteFlag";
		var childFrame=document.getElementById('List').contentWindow;
	    var checkBoxList = childFrame.document.getElementsByName(deleteFlags);  
	    var checkIds="";  
	    for (var i=0;i<checkBoxList.length;i++){
	        if (checkBoxList[i].checked){
	            if(i==0)
	            {
	            	checkIds = checkBoxList[i].value + ",";
	            }
	            else
	            {
	            	checkIds = checkIds + "," + checkBoxList[i].value;
	            }
	            
	        }
	    } 
		var ParentForm = window.dialogArguments.document.getElementById("selectgoods");
		//alert(checkIds);
		ParentForm.value=checkIds;
        window.returnValue=1;
        onReturn();
        
    }


  • 大小: 7.8 KB
  • 大小: 16.5 KB
  • 大小: 17 KB
分享到:
评论
5 楼 QQ1145306946 2013-06-04  
能不能加你的QQ呢?有几个问题想问你的,呵呵
4 楼 康敏栋 2013-06-03  
QQ1145306946 写道
请问最后的代码function updateData() {是放在PuerchaseGoodsSelect.jsp里吗?


对,就是里面的点击“确定”时的function
3 楼 QQ1145306946 2013-06-01  
请问最后的代码function updateData() {是放在PuerchaseGoodsSelect.jsp里吗?
2 楼 康敏栋 2013-05-28  
QQ1145306946 写道
请问,这样的功能是否用购物车的方法来做呢?

不是,就是普通的js实现
1 楼 QQ1145306946 2013-05-28  
请问,这样的功能是否用购物车的方法来做呢?

相关推荐

Global site tag (gtag.js) - Google Analytics