Examples are as follows:
/* $ (' #app1 '). Change (function () {appsdetails["App1"] = $ (' #app1 '). val ();}) $ (' #app2 '). Change (function () {appsdetails["app2"] = $ (' #app2 '). val ();}) $ (' #app3 '). Change (function () {appsdetails["app3"] = $ (' #app3 '). val ();}) $ (' #app4 '). Change (function () {appsdetails["app4"] = $ (' #app4 '). val ();}) $ (' #app5 '). Change (function () {appsdetails["app5"] = $ (' #app5 '). val ();}) $ (' #app6 '). Change (function () {appsdetails["app6"] = $ (' #app6 '). Val (),}) */function Getappsdetails () {//use eval to Execute all change functionvar arr = Object.getownpropertynames (Appsdetails), for (var i = 0; i < arr.length; i++) {VA R evalstr = "appsdetails[" "+arr[i]+" '] = $ (' # ' +arr[i]+ "'). Val ();" eval (EVALSTR);} Return json.stringify (appsdetails);}
For example, there are a lot of repetitive code, only the difference between some variables can be performed using the Eval method, the code will be much less.
Good at using JS's eval method