The d10 +... - d25 said
D10 d11 + - d14 d13 + - d15 + d16 - d12 d17 + d18 - d19 + d20 - d21 + d22 - perhaps a + d24 d25
The great god, help me modify the trouble, thank you infinite!
Requirements:
A1 +... + a4, on behalf of the continuous addition: a1 + a2, a3 and a4
C1 +... - c4 above MianAn case, interval and subtract: c1 and c2 + c3 c4
The function calc (obj) {
Var STR=obj. The innerText;
If (/^ \ s * $/. The test (STR))
return 0;
If (STR [0]=="=") {
Obj. The innerText=eval (STR) slice (1) the replace (([a-z] +)/(\ d +) ([\ + \ \ \ */]) \. {3} ([\ + \ \ \ */]] ([a-z] +) (\ d +)/ig, the function (s, w1, n1, c1 and c2, w2, n2) {
Var arr=[];
N1=parseInt (n1, 10);
N2=parseInt (n2, 10);
For (var I=n1; I & lt; N2. I++)
Arr. Push (w1 + I);
Return arr. Join (c1) + c2 + w2 + n2;
}). Replace (/[a-z] + \ d +/ig, the function (s) {
Return "(" + calc (document. GetElementById (s)) +") ";
}));
}
Return obj. The innerText;
}
Var td=document. QuerySelectorAll (" # TAB td ");
For (var I=0, len=td. Length; I & lt; Len. I++) {
[I] calc (td);
}
</script>
CodePudding user response:
The function calc (obj) {
Var STR=obj. The innerText;
If (/^ \ s * $/. The test (STR))
return 0;
If (STR [0]=="=") {
Obj. The innerText=eval (STR) slice (1) the replace (([a-z] +)/(\ d +) ([\ + \ \ \ */]) \. {3} ([\ + \ \ \ */]] ([a-z] +) (\ d +)/ig, the function (s, w1, n1, c1 and c2, w2, n2) {
N1=parseInt (n1, 10);
N2=parseInt (n2, 10);
Var STR=w1 + n1;
For (var I=n1 + 1; I & lt;=n2; I++)
STR +=((n2 - I) % 2==0? C2: c1) + w1 + I;
return str;
}). Replace (/[a-z] + \ d +/ig, the function (s) {
Return "(" + calc (document. GetElementById (s)) +") ";
}));
}
Return obj. The innerText;
}
Var td=document. QuerySelectorAll (" # TAB td ");
For (var I=0, len=td. Length; I & lt; Len. I++) {
[I] calc (td);
}
</script>