Medical web site - 1131Chapter 42 .Global Functions and Statements variable flags
1131Chapter 42 .Global Functions and Statements variable flags are set elsewhere for isNav4 and isIE4. The function must create a valid reference to the object depending on which browser the user runs: function getReference(objName) { if (navigator.appVersion.charAt(0) == 4 ) { if (navigator.appName == Netscape ) { var range = var styleObj = } else { var range = .all var styleObj = .style } var theObj = eval( document + range + . + objName + styleObj) return theObj } return null } In the NN4 branch of the preceding example, the variables range and styleObj are assigned empty strings; for the Microsoft branch, each variable assumes the components that must be inserted into an object reference for the Microsoft syntax. If the components are concatenated without the eval()function, the result simply is a concatenated string (which is not the same as the object reference). By forcing an additional evaluation with the eval() function, the script invokes JavaScript to see if one more level of evaluation is needed. If JavaScript finds that the evaluation of that string is a valid object reference, it returns the reference as the result; otherwise, the function returns undefined. The eval() function can evaluate any JavaScript statement or expression stored as a string. This includes string equivalents of arithmetic expressions, object value assignments, and object method invocation. I do not recommend that you rely on the eval()function, however, because this function is inherently inefficient (from the standpoint of performance). Fortunately, you may not need the eval()function to get from a string version of an object s name to a valid object reference. For example, if your script loops through a series of objects whose names include serial numbers, you can use the object names as array indices rather than use eval()to assemble the object references. The inefficient way to set the value of a series of fields named data0, data1, and so on, is as follows: function fillFields() { var theObj for (var i = 0; i < 10; i++) { theObj = eval( document.forms[0].data + i) theObj.value = i } } A more efficient way is to perform the concatenation within the index brackets for the object reference: function fillFields() { for (var i = 0; i < 10; i++) { document.forms[0].elements[ data + i].value = i } } eval()
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.