eval Method
Evaluates JScript code and executes it. eval(codeString) The required codeString argument is a string value that contains valid JScript code. This string is parsed by the JScript parser and executed.Res
The eval function allows dynamic execution of JScript source code. For example, the following code creates a new variable mydate that contains a Date object: eval("var mydate = new Date();");
The code passed to the eval method is executed in the same context as the call to the eval method.js中没有elements()

解决方案 »

  1.   

    计算一个表达式的值并返回结果。[result = ]Eval(expression)
    参数
    result 
    可选项。是一个变量,用于接受返回的结果。如果未指定结果,应考虑使用 Execute 语句代替。 
    expression 
    必选项。可以是包含任何有效 VBScript 表达式的字符串。 
    说明
    在 VBScript 中,x = y 可以有两种解释。第一种方式是赋值语句,将 y 的值赋予 x。第二种解释是测试 x 和 y 是否相等。如果相等,result 为 True;否则 result 为 False。Eval 方法总是采用第二种解释,而 Execute 语句总是采用第一种。注意   在Microsoft® JScript™ 中不存在这种比较与赋值的混淆,因为赋值运算符 (=) 与比较运算符 (==) 不同。
    下面的例子说明了 Eval 函数的用法: Sub GuessANumber
       Dim Guess, RndNum
       RndNum = Int((100) * Rnd(1) + 1)
       Guess = CInt(InputBox("Enter your guess:",,0))
       Do
          If Eval("Guess = RndNum") Then
             MsgBox "祝贺你!猜对了!"
             Exit Sub
          Else
             Guess = CInt(InputBox("对不起,请再试一次",,0))
          End If
       Loop Until Guess = 0
    End Sub有elements()个函数吗?
      

  2.   


    elements
    An array of objects corresponding to form elements (such as checkbox, radio, and Text objects) in source order.
    属性源 Form 
    只读  
    实现版本 Navigator 2.0 描述
    You can refer to a form's elements in your code by using the elements array. This array contains an entry for each object (Button, Checkbox, FileUpload, Hidden, Password, Radio, Reset, Select, Submit, Text, or Textarea object) in a form in source order. Each radio button in a Radio object appears as a separate element in the elements array. For example, if a form called myForm has a text field and two checkboxes, you can refer to these elements myForm.elements[0], myForm.elements[1], and myForm.elements[2].
    Although you can also refer to a form's elements by using the element's name (from the NAME attribute), the elements array provides a way to refer to Form objects programmatically without using their names. For example, if the first object on the userInfo form is the userName Text object, you can evaluate it in either of the following ways:userInfo.userName.value
    userInfo.elements[0].value The value of each element in the elements array is the full HTML statement for the object.
      

  3.   

    eval
    Evaluates a string of JavaScript code in the context of this object.
    方法源 Object 
    实现版本 Navigator 3.0, LiveWire 1.0
    Navigator 4.0, Netscape Server 3.0: removed as 方法源 objects; retained as global function. 语法
    eval(string) 
    参数
    string Any string representing a JavaScript expression, statement, or sequence of statements. The expression can include variables and properties of existing objects. 描述
    The argument of the eval method is a string. If the string represents an expression, eval evaluates the expression. If the argument represents one or more JavaScript statements, eval performs the statements. Do not call eval to evaluate an arithmetic expression; JavaScript evaluates arithmetic expressions automatically.
    If you construct an arithmetic expression as a string, you can use eval to evaluate it at a later time. For example, suppose you have a variable x. You can postpone evaluation of an expression involving x by assigning the string value of the expression, say "3 * x + 2", to a variable, and then calling eval at a later point in your script.eval is also a global function, not associated with any object. 
    NOTE: In Navigator 2.0, eval was a top-level function. In Navigator 3.0 eval was also a method of every object. The ECMA-262 standard for JavaScript made eval available only as a top-level function. For this reason, in Navigator 4.0, eval is once again a top-level function. In Navigator 4.02, obj.eval(str) is equivalent in all scopes to with(obj)eval(str), except of course that the latter is a statement, not an expression. 
    示例
    示例 1. The following example creates breed as a property of the object myDog, and also as a variable. The first write statement uses eval('breed') without specifying an object; the string "breed" is evaluated without regard to any object, and the write method displays "Shepherd", which is the value of the breed variable. The second write statement uses myDog.eval('breed') which specifies the object myDog; the string "breed" is evaluated with regard to the myDog object, and the write method displays "Lab", which is the value of the breed property of the myDog object.
    function Dog(name,breed,color) {
       this.name=name
       this.breed=breed
       this.color=color
    }
    myDog = new Dog("Gabby")
    myDog.breed="Lab"
    var breed='Shepherd'
    document.write("<P>" + eval('breed'))
    document.write("<BR>" + myDog.eval('breed')) 示例 2. The following example uses eval within a function that defines an object type, stone. The statement flint = new stone("x=42") creates the object flint with the properties x, y, z, and z2. The write statements display the values of these properties as 42, 43, 44, and 45, respectively.function stone(str) {
       this.eval("this."+str)
       this.eval("this.y=43")
       this.z=44
       this["z2"] = 45
    }
    flint = new stone("x=42")
    document.write("<BR>flint.x is " + flint.x)
    document.write("<BR>flint.y is " + flint.y)
    document.write("<BR>flint.z is " + flint.z)
    document.write("<BR>flint.z2 is " + flint.z2)