When you write an HTML program, you need to convert string-type data to int-type data and then perform four hybrid operations. For example:
VaR A = "12"; var B = "23 ";
Alert (A + B );
The output in the above example is "1223". This can only be a string connection. If eval () is used, will it always report an error like Nan?
I think yes, because this is not the case, because you have not figured out how to use the eval () function.
My program has an example like this: We get data from the front-end text box, and then perform four arithmetic operations on the data obtained from the data.
1 nowYear = document.getElementById("TxtStyleTwoY").value;2 nowMonth = document.getElementById("TxtStyleTwoM").value;3 nowDay = document.getElementById("TxtStyleTwoD").value;
Arithmetic Operations:
1 If (nowyear = starty) 2 {3 if (nowmonth> startm) 4 {5 for (M = startm; m <nowmonth; ++ m) // calculate the total number of days in a month. 6 {7 days = days + modays [m]; 8} 9 days + = (nowday-startd); 10 document. getelementbyid ("Answer "). value = days + "days at" + nowyear + "year" + nowmonth + "month" + nowday + "day. ";
11} 12 else if (nowmonth = startm) 13 {14 if (nowday> = startd) 15 {16 days = days + nowday-startd; // calculate the number of days in the last month 17 document. getelementbyid ("Answer "). value = days + "days at" + nowyear + "year" + nowmonth + "month" + nowday + "day. "; 18} 19 else20 document. getelementbyid ("Answer "). value = "date error! "; 21 22}
The above is to directly obtain the string, in fact, we only need to make a small conversion to the above Code, the program can run perfectly:
1 nowYear = eval(document.getElementById("TxtStyleTwoY").value);2 nowMonth = eval(document.getElementById("TxtStyleTwoM").value);3 nowDay = eval(document.getElementById("TxtStyleTwoD").value);
I don't know if I have made it clear that the document is not very good. Don't be surprised... *_*