`

工资表达式 字符串

阅读更多

脚本:

 

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>

分享到:
评论

相关推荐

    Delphi 计算字符串表达式

    ### Delphi 计算字符串表达式 在 Delphi 编程语言中,处理字符串表达式的计算是一项常见的任务,尤其是在需要动态解析数学表达式的情况下。本文将深入探讨如何编写一个简单的数值字符表达式计算函数,该函数能够...

    C#字符串计算公式处理

    字符串是不可变的数据类型,可以通过索引访问其字符,并且支持多种方法,如`Substring`用于提取子字符串,`Replace`用于替换特定字符或子串,以及`Split`用于分割字符串成字符串数组。在处理计算公式时,`Split`方法...

    C#内插字符串的简单使用

    内插字符串表达式可以插入任何类型的数据,包括基本类型、对象实例甚至是复杂的表达式结果。下面是一个简单的示例: ```csharp var name = "小胡子"; var age = 26; var email = "xiaohuzi@xiaohuzi.com"; var ...

    C# 6.0 字符串 String Interpolation

    C# 6.0引入了一种新的字符串操作方式——字符串插值(String Interpolation),它为程序员提供了更直观、简洁的格式化字符串方法。在之前的版本中,我们通常使用`String.Format`或`StringBuilder`来构造包含变量的...

    Delphi7字符串四则运算解析

    1. **字符串表达式解析**:在Delphi7中,我们经常需要将用户的输入,如字符串形式的数学公式,转换为可执行的计算。这通常涉及到字符串处理和表达式解析。例如,用户可能输入"2 + 3 * 4",程序需要识别出加法和乘法...

    oracle字符串操作.pdf

    Oracle数据库系统中,字符串操作是数据库查询和管理中的基础且重要的一部分。在本文中,我们将深入探讨Oracle中的字符串处理函数和相关知识,这些知识对于数据库管理员和开发人员来说至关重要。 首先,DQL,即Data ...

    c# 表达式(公式)计算

    7. **类型转换**:在计算过程中,不同类型的值可能需要进行转换,例如从字符串到数值类型。`Convert`类或`int.TryParse`等方法可以帮助完成这些转换。 8. **编译和运行时计算**:C#可以通过`Compile`方法将表达式树...

    Python字符串格式化输出代码实例

    字符串格式化是将数据转换为字符串的过程,这在编程中非常常见,尤其是在构建输出消息或处理用户输入时。本文将详细介绍Python中字符串格式化的几种常用方法,并通过实例代码来演示它们的用法。 首先,Python中最...

    js手工调薪输入表达式代码.zip

    2. **字符串处理**:用户输入的表达式通常以字符串形式接收。JS提供了丰富的字符串方法,如`split()`用于按分隔符拆分字符串,`trim()`去除两端空白,以及`replace()`替换特定字符等,这些都可能在解析用户输入时...

    JS验证URL正则表达式.txt

    在给定的部分内容中,定义了一个JavaScript函数`functionIsURL(str_url)`,该函数利用正则表达式来验证传入的字符串是否为一个合法的URL。 ##### 正则表达式结构拆解: - **协议部分**:`^((https|http|ftp|rtsp|...

    Access表达式.pdf

    以下是一些关于Access表达式的知识点,主要涵盖基本操作、简单应用、日期函数、字符串函数、统计函数以及SQL子查询。 **基本操作(表)** 1. 使用`DateSerial`函数可以计算特定日期,例如`DateSerial(Year(Date())-...

    oracle函数速查

    `LENGTH()`返回字符串的长度,`TRIM()`去除字符串两端的空白字符,`LOWER()`和`UPPER()`用于大小写的转换,`REPLACE()`替换字符串中的特定子串,以及`REGEXP_LIKE()`用于正则表达式的匹配。 在实际应用中,熟练掌握...

    实验三PHP运算符和表达式.pdf

    例如,如果字符串包含双引号,可以使用反斜杠(`\`)作为转义字符,如`\"`。在任务2中,学生需要编写代码输出包含转义双引号的字符串"祝你生日快乐!"。 3. **自增自减运算符**: PHP中的自增`++`和自减`--`运算符...

    php提取字符串中网站url地址的方法

    // 正则表达式匹配字符串中的URL preg_match_all("/http:[\/]{2}[a-z]+[.]{1}[a-z\d\-]+[.]{1}[a-z\d]*[\/]*[A-Za-z\d]*[\/]*[A-Za-z\d]*/", $postInfo['answer2'], $array2); print_r($array2); ``` 这段代码中的...

    常用正则表达式.text

    正则表达式是一种强大的文本处理工具,能够帮助我们完成各种复杂的字符串搜索与替换功能。在本篇文章中,我们将详细介绍一些常用的正则表达式及其应用场景。 #### 二、具体知识点分析 ##### 1. 数字验证 - **整数...

    C语言程序设计标准教程

     本程序中用赋值语句给num和name两个成员赋值,name是一个字符串指针变量。用scanf函数动态地输入sex和score成员值,然后把boy1的所有成员的值整体赋予boy2。最后分别输出boy2 的各个成员值。本例表示了结构变量的...

    4.选择1

    5. Python字符串处理:`eval()`函数可以将字符串转换为可执行的Python表达式,但使用时需谨慎,因为可能会引入安全风险。 6. 逻辑表达式的等价性:理解逻辑表达式之间的等价关系,例如`x!=y&gt;5`等价于`x!=y and y&gt;5`...

    Oracle100个常用函数.docx

    **语法**: RPAD(字符串, 总长度, 填充字符)/LPAD(字符串, 总长度, 填充字符) **示例**: 对字符串'gao'进行左右两侧填充'*'至总长度为17。 ```sql SQL&gt; SELECT LPAD(RPAD('gao', 10, '*'), 17, '*') FROM DUAL; ``` ...

    程序设计练习题

    3. **第7次-CSP201409_3字符串匹配.doc** - 又一个关于字符串处理的题目,可能需要掌握字符串的高级操作,比如正则表达式、动态规划方法在字符串匹配中的应用等。 4. **第2次-CSP201409-1相邻数对.doc** - 这可能是...

Global site tag (gtag.js) - Google Analytics