工资表达式 字符串
来源:互联网 发布:食堂订餐软件 编辑:程序博客网 时间:2024/05/16 11:51
脚本:
var tempvalue=""; //文本框显示
var temp_key = "";
var all_str=""; //用于验证四则运算合法 将所有代码转化成数字
var key_array = new Array();
var value_array = new Array();
var row=0; //数组标记 增加时加1,撤销时减1
//选择计算器
function setFormula(num){
key_array.push(num);
value_array.push(num);
if(temp_value == ""){
temp_value = value_array[row];
}else{
temp_value += value_array[row];
}
if(temp_key == ""){
temp_key = key_array[row];
}else{
temp_key += key_array[row];
}
document.getElementById("accountDetailVO.formulaText").value = temp_value; //中文显示
document.getElementById("accountDetailVO.formula").value = temp_key; //保存到数据库
row++;
}
//选择工资项
function setFormulaItem(num){
var items = document.getElementById("accountDetailVO.item");
var itemName = "";
var item = "";
for(var i = 0; i < items.length; i++){
if(items[i].selected){
itemName = document.all.item.options[i].text;
item = document.all.item.options[i].value;
}
}
key_array.push(item);
value_array.push(itemName);
if(temp_value == ""){
temp_value = value_array[row];
}else{
temp_value += value_array[row];
}
if(temp_key == ""){
temp_key = key_array[row];
}else{
temp_key += key_array[row];
}
document.getElementById("accountDetailVO.formulaText").value = temp_value; //中文显示
document.getElementById("accountDetailVO.formula").value = temp_key; //保存到数据库
row++;
}
//撤销
function clk_cancel(){
if(row != 0){ //撤销时从数组中删除数据
var end_key = key_array.pop();
var end_value = value_array.pop();
temp_key = temp_key.substring(0,temp_key.lastIndexOf(end_key));
temp_value = temp_value.substring(0,temp_value.lastIndexOf(end_value));
document.getElementById("accountDetailVO.formula").value = temp_key; //保存到数据库
document.getElementById("accountDetailVO.formulaText").value = temp_value; //显示
row--;
}
}
function clk_delete(){
document.getElementById("accountDetailVO.formula").value = "";
document.getElementById("accountDetailVO.formulaText").value = "";
temp_value = "";
temp_key = "";
}
function clk_save(){
var parent_window = parent.dialogArguments;
var formula = parent_window.document.getElementById("accountDetailVO.formula");
var formulaText = parent_window.document.getElementById("accountDetailVO.formulaText");
var str=temp_key;
str = str.replace(/[ ]/g,"");
if(str == ""){
alert("表达式为空,请重新编辑");
return false;
}
if(/^(\(?[+-]?\(?\w+\.?\w*\)?[+-/\*]\(?[+-]?\(?\w+\.?\w*\)?)+$/.test(str)){
}else{
alert("表达式格式不正确,请修改");
return false;
}
if(formula != null){
formula.value = temp_key;
}
if(formulaText != null){
formulaText.value = temp_value;
}
window.close();
}
function clk_close(){
window.close();
}
function editForlula(){
var formula = document.getElementById("accountDetailVO.formula");
var formulaText = document.getElementById("accountDetailVO.formulaText");
temp_key = formula.value;
temp_value = formulaText.value;
}
-----------------------------------------------------------------页面-----------------------------------------------------------
<body onload="editForlula()">
<form name="accountDetailForm" method="post" action="">
<html:hidden name="accountDetailForm" property="accountDetailVO.formula"/>
<table width="99%" border="0" cellspacing="1" cellpadding="0"
class="ReportTable" align="center">
<tr class="ButtonTableContent">
<td align="right">
<input name="fh" class="Button2_mouseout"
onmouseover="this.className='Button1_mouseover'"
onmouseout="this.className='Button2_mouseout'"
onmousedown="this.className='Button1_mousedown'"
onmouseup="this.className='Button1_mouseup'" type="button"
value="确 定" onclick="javascript:clk_save();">
<input name="fh" class="Button2_mouseout"
onmouseover="this.className='Button1_mouseover'"
onmouseout="this.className='Button2_mouseout'"
onmousedown="this.className='Button1_mousedown'"
onmouseup="this.className='Button1_mouseup'" type="button"
value="清 除" onclick="javascript:clk_delete();">
<input name="fh" class="Button2_mouseout"
onmouseover="this.className='Button1_mouseover'"
onmouseout="this.className='Button2_mouseout'"
onmousedown="this.className='Button1_mousedown'"
onmouseup="this.className='Button1_mouseup'" type="button"
value="撤 销" onclick="javascript:clk_cancel();">
<input name="fh" class="Button2_mouseout"
onmouseover="this.className='Button1_mouseover'"
onmouseout="this.className='Button2_mouseout'"
onmousedown="this.className='Button1_mousedown'"
onmouseup="this.className='Button1_mouseup'" type="button"
value="关 闭" onclick="javascript:clk_close();">
</td>
</tr>
</table>
<TABLE width="30%" border=2 width=50 height=60 cellpadding=1
cellspacing=5 align="center">
<tr>
<td height="172" colspan="5"><html:textarea name="accountDetailForm"
property="accountDetailVO.formulaText" rows="10" cols="60"
styleId="isLongerTah100:公式" readonly="true" /></td>
<td></td>
</tr>
<tr>
<td colspan="5">
工资项名称
</td>
</tr>
<tr>
<td width="250" rowspan="6"><bean:define
id="itemList" name="accountDetailForm"
property="itemList" /> <html:select name="accountDetailForm"
property="accountDetailVO.item" multiple="true" size="10"
styleId="item" style="width:200px" ondblclick="setFormulaItem(this.value)" >
<html:options collection="itemList" property="key"
labelProperty="value" />
</html:select>
</td>
<TD colspan="2" align="center" ><input name="btnClear" type="Button"
value=" ( " onclick="setFormula('(')"></TD>
<TD colspan="2" align="center"><input name="btnClearEntry" type="Button"
value=" ) " onclick="setFormula(')')"></TD>
</tr>
<TR>
<TD ><input name="btnSeven" type="Button" value=" 7 "
onclick="setFormula('7')"></TD>
<TD><input name="btnEight" type="Button" value=" 8 "
onclick="setFormula('8')"></TD>
<TD><input name="btnNine" type="Button" value=" 9 "
onclick="setFormula('9')"></TD>
<TD><input name="btnNeg" type="Button" value=" + "
onclick="setFormula('+')"></TD>
</TR>
<TR>
<TD ><input name="btnFour" type="Button" value=" 4 "
onclick="setFormula('4')"></TD>
<TD><input name="btnFive" type="Button" value=" 5 "
onclick="setFormula('5')"></TD>
<TD><input name="btnSix" type="Button" value=" 6 "
onclick="setFormula('6')"></TD>
<TD align=middle><input name="btnPlus" type="Button"
value=" - " onclick="setFormula('-')"></TD>
</TR>
<TR>
<TD ><input name="btnOne" type="Button" value=" 1 "
onclick="setFormula('1')"></TD>
<TD><input name="btnTwo" type="Button" value=" 2 "
onclick="setFormula('2')"></TD>
<TD><input name="btnThree" type="Button" value=" 3 "
onclick="setFormula('3')"></TD>
<TD align=middle><input name="btnMultiply" type="Button"
value=" * " onclick="setFormula('*')"></TD>
</TR>
<TR>
<TD colspan="2"><input name="btnZero" type="Button" value=" 0 "
onclick="setFormula('0')"></TD>
<TD><input name="btnDecimal" type="Button" value=" . "
onclick="setFormula('.')"></TD>
<TD><input name="btnDecimal" type="Button" value=" / "
onclick="setFormula('/')"></TD>
</TR>
</TABLE>
</FORM>
</body>
- 工资表达式 字符串
- 【字符串处理】【模拟】NBA工资
- 工资
- 工资
- 工资
- 工资
- 如何计算字符串表达式
- 计算字符串表达式
- 字符串中的正则表达式
- 字符串转换为表达式
- 正则表达式取字符串
- 正则表达式匹配字符串
- ${}el表达式切割字符串
- 字符串表达式求值
- 解析算术表达式字符串
- 排除字符串正则表达式
- 字符串表达式计算
- [收藏]字符串表达式求值
- Java面向对象编程(一)
- 《Effective C++》学习笔记
- 1062. Talent and Virtue (25)
- 【node.js】使用node.js搭建一个本地web服务器
- 关于JQuery中的$.each()与$().each的理解
- 工资表达式 字符串
- 关于class.getResourceAsStream() 与class.getClassLoader().getResourceAsStream()区别
- Android Permission访问权限大全
- ubuntu 14.04 設定hostname
- mybatis给对象赋值
- 乱码问题(1),MyEclipse中乱码
- C# 的逻辑判断语句 -5
- Android群英传——第四章动态改变ListView的布局
- 机器学习入门