javascript手冊-l[2]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 longj 的 blog

windowreference is a valid way of referring to a window, as described in the window object.

property of

  • frame, history, radio, select, string, window objects
  • anchors, elements, forms, frames, links, options arrays

    描述

    the length property is an integer that specifies one of the following:

  • the number of elements on a form (form 1 of the 语法).
  • the number of frames within a frame (form 2 of the 语法). a frame that does not load a document containing a <frameset> tag always has a length of 0.
  • the number of entries in a history object (form 3 of the 语法).
  • the number of radio buttons in a radio object (form 4 of the 语法).
  • the number of options in a select object (form 5 of the 语法).
  • the length of a string object (form 6 of the 语法).
  • the number of frames in a parent window (form 7 of the 语法).
  • the number of entries in one of the array properties (all other 语法 forms).

    length is always a read-only property.

    for a null string, length is zero. for a select object, the values returned by form 5 and form 14 of the 语法 are the same. for a window containing frames, the values returned by form 7 and form 12 of the 语法 are the same. for a form object, the values returned by form 1 and form 9 of the 语法 are the same. for a frame containing frames, the values returned by form 2 and form 11 of the 语法 are the same.

    例子

    in the following example, the getchoice() function uses the length property to iterate over every element in the musictype array. musictype is a select element on the musicform form.

    function getchoice() {
       for (var i = 0; i < document.musicform.musictype.length; i++) {
          if (document.musicform.musictype.options[i].selected == true) {
             return document.musicform.musictype.options[i].text
          }
       }
    }
    

    the following example displays 8 in an alert dialog box:

    var x="netscape"
    alert("the string length is " + x.length)
    

    link method

    creates an htm hypertext link that jumps to another url.

    语法

    linktext.link(hrefattribute)

    linktext is any string or a property of an existing object.

  • 本文关键:javascript
      相关方案
    Google
     

    本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

    go top