There are five kinds of forms
string formula
Str1="=b199"
Str2="=b142 - b143"
Str3="=c18 + c78 + c84 + c125"
Str4="=b261 + b262 + b263 + b264 + b265 + b266 + b267 + b268 + b269 + b270 + b271 + b272 + b273 - b274"
Str5="=b2 +... + b17 "
& lt; Table>The serial number & lt;/td> Value & lt;/td> The formula & lt;/td> 1 & lt;/td> 2 & lt;/td>
.
CodePudding user response:
Is not quite easy, can write out will point js, id 1 ~ 100, in order to loop for dom, remove the td value converted to the number of add and subtractCodePudding user response:
A function need to deal with these 5 kinds of circumstances, at the same time the regular expression is not well. Don't come out,Str1="=b199"
Str2="=b142 - b143"
Str3="=c18 + c78 + c84 + c125"
Str4="=b261 + b262 + b263 + b264 + b265 + b266 + b267 + b268 + b269 + b270 + b271 + b272 + b273 - b274"
Str5="=b2 +... + b17"
CodePudding user response:
Split () the near the b out what thingCodePudding user response:
//now supports addition, subtraction, multiplication, division
Var str6='=b1 + c2 b2/c1 *'
Alert (strSplit (str6))
//the console. The log ()
The function strSplit (STR) {
If (STR [0]! {
='=')Return the STR
}
Var name_id='
Var sum='
Var types=[' + ', '-' and '*', '/']//modify the algorithm of support here
For (var I=1; iIf (types. IndexOf (STR) [I]!=1) {
The sum +=getNum (name_id) + STR [I]
Name_id='
} else {
Name_id +=STR [I]
}
If (I==STR. Length - 1) {
The sum +=getNum (name_id)
}
}
Return the eval (sum)
}
The function getNum (id) {
Return the document. The getElementById (id). The innerText
}
CodePudding user response:
1: the first letter and number=replace null2: the eval () is the result directly
CodePudding user response:
Simple processing:
<meta charset="utf-8"/& gt;Formula test
<body>