这个该怎么取值呢?我的js水平太菜!!请大神指点一二。。
jsp源码:
<div id="tabb">
<fieldset>
<legend>摆货详情</legend>
<div style="width:100%; font-family:'宋体';font-size:12px;">
物料总数量:
<input type="text" name="TextField_1" value="19" id="TextField_1" style="display:none"/>
<input type="text" name="receiptQuan" value="<s:property value="#session.materiel.inventory"/>" id="receiptQuan" style="border-bottom:0" readonly="true" class="input1"/>
物料名称:
<input type="text" name="TextField_2" value="<s:property value="#session.materiel.matname"/>" id="TextField_2" style="border-bottom:0" readonly="true" class="input1"/>
<input type="text" name="TextField_3" value="5" id="TextField_3" style="display:none"/>
物料编号:
<input type="text" name="TextField_2" value="<s:property value="#session.materiel.id"/>" id="TextField_2" style="border-bottom:0" readonly="true" class="input1"/>
</div>
<form name="form2">
<ul>
<s:if test="#session.depotareas == null">
<s:fielderror key="depotGetError"/>
</s:if>
//循环仓位可以
<s:iterator value="#session.storageList" var="storage">
<li style=" height: 100px; width:150px; float:left; border: 1px solid yellow; text-align: center">
//此处是可以入库的仓位
<s:if test="#storage.stoarea<400">
//输入数量的地方
<input type="text" class="input2" style=" margin-left: -40px">
//记住仓位编号的地方隐藏域
<input id="storagesId" value="<s:property value="#storage.id"/>" style=" height:0px" type="hidden">
<img src="images/nos/103.gif" style=" margin: 0px auto;" align="top"><tr/>
</s:if>
//不能入库的仓位
<s:if test="#storage.stoarea>=400">
<input type="text" class="input3" style=" border: 0px"/>
<img src="images/nos/102.gif" style=" margin: 0px auto;" align="top"><tr/>
</s:if>
//仓位名称
<p style=" height: 8px; font-size: 12px; margin-top: -2px">仓位:<s:property value="#storage.storageid"/></p>
</li>
</s:iterator>
</ul>
</form>
</fieldset>
</div>
2、你用于存放未满仓库ID的元素,该元素的id 统一都为storagesId。这样你是没法通过getElementByid("storagesId")取到所有仓库元素的。并且就算取到了,也无法与上面提到的输入数量进行对应。建议对源代码进行改造。例如:
将:
<s:if test="#storage.stoarea<400">
//输入数量的地方
<input type="text" class="input2" style=" margin-left: -40px">
//记住仓位编号的地方隐藏域
<input id="storagesId" value="<s:property value="#storage.id"/>" style=" height:0px" type="hidden">
<img src="images/nos/103.gif" style=" margin: 0px auto;" align="top"><tr/>
</s:if>
<s:if test="#storage.stoarea<400">
//输入数量的地方
<input id="<s:property value="#storage.id"/>" type="text" class="input2" style=" margin-left: -40px">
//直接将输入域的id设置为仓库id
<img src="images/nos/103.gif" style=" margin: 0px auto;" align="top"><tr/>
</s:if>
<style>
.input2{ width:120px;margin-left:0px }
</style>
<form name="form2" onsubmit="return OnSubmit(this)" >
<div>
<ul>
<li style=" height: 100px; width:150px; float:left; border: 1px solid yellow; text-align: center">
<input name="storages" type="text" class="input2" >
<input name="storagesId" value="1" style=" height:0px" type="hidden">
<p style=" height: 8px; font-size: 12px; margin-top: -2px">仓位:11</p>
</li>
<li style=" height: 100px; width:150px; float:left; border: 1px solid yellow; text-align: center">
<input name="storages" type="text" class="input2" >
<input name="storagesId" value="2" style=" height:0px" type="hidden">
<p style=" height: 8px; font-size: 12px; margin-top: -2px">仓位:22</p>
</li>
<li style=" height: 100px; width:150px; float:left; border: 1px solid yellow; text-align: center">
<input name="storages" type="text" class="input2" >
<input name="storagesId" value="3" style=" height:0px" type="hidden">
<p style=" height: 8px; font-size: 12px; margin-top: -2px">仓位:33</p>
</li>
</ul>
</div>
<input type=submit value="提交" >
</form>
<script>
var Max=100;// 物料的总数量
function OnSubmit(f){
var sum=0;
for(var i=0;i<f.storagesId.length;i++){
alert( f.storagesId[i].value +':' + f.storages[i].value ); //测试 输出 storagesId:storages
sum+=parseInt(f.storages[i].value)
[解决办法]
0;
}
//不能大于物料的总数量
if(sum >Max ) {
alert('不能大于物料的总数量');
return false;
}
}
</script>