文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>2008-12-22 JQuery 学习 Vol.3

2008-12-22 JQuery 学习 Vol.3

时间:2008-12-22  来源:Givemefive

1. 修改DOM元素的属性
1.1 attr
    1.1.1 attr(name)
        Obtains the values assigned to the specified attribute for the first element in the matched set.
    Parameters
        name (String) The name of the attribute whose value is to be fetched.
    Returns
        The value of the attribute for the first matched element. The value undefined is returned if the matched set is empty or the attribute doesn’t exist on the first element.

    1.1.2 attr(name,value)
        Sets the named attribute onto all elements in the wrapped set using the passed value.
    Parameters
        name (String) The name of the attribute to be set.
        value (String|Object|Function) Specifies the value of the attribute. This can be any Java-Script expression that results in a value, or it can be a function. See the following discussion for how this parameter is handled.
    Returns
        The wrapped set.
    1.1.3 attr(attributes)
        Sets the attributes and values specified by the passed object onto all elements of the matched set
    Parameters
        attributes (Object) An object whose properties are copied as attributes to all elements in the wrapped set
    Returns
        The wrapped set

1.2 jQuery attr() normalized-access names
class      className
cssFloat   styleFloat for IE, cssFloat for others (when used with .css)
float      styleFloat for IE, cssFloat for others (when used with .css)
for        htmlFor
maxlength  maxLength
readonly   readOnly
styleFloat styleFloat for IE, cssFloat for others (when used with .css)

1.3 removeAttr
    removeAttr(name)
        Removes the specified attribute from every matched element
    Parameters
        name (String) The name of the attribute to be removed
    Returns
        The wrapped set

2. 修改DOM元素的样式表
2.1 addClass
    addClass(names)
        Adds the specified class name or class names to all elements in the wrapped set
    Parameters
        names (String) A string containing the class name to add or, if multiple class names are to be added, a space-delimited string of class names
    Returns
        The wrapped set

2.2 removeClass
    removeClass(names)
        Removes the specified class name or class names from each element in the wrapped set
    Parameters
        names (String) A string containing the class name to remove or, if multiple class names are to be removed, a space-delimited string of class names
    Returns
        The wrapped set

2.3 toggleClass
    toggleClass(name)
        Adds the specified class name if it doesn’t exist on an element, or removes the name from elements that already possess the class name. Note that each element is tested individually, so some elements may have the class name added, and others may have it removed.
    Parameters
        name (String) A string containing the class name to toggle.
    Returns
        The wrapped set.

2.4 css
    2.4.1 css(name,value)
        Sets the named CSS style property to the specified value for each matched element.
    Parameters
        name (String) The name of the CSS property to be set.
        value (String|Number|Function) A string, number, or function containing the property value. If a function is passed as this parameter, it will be invoked for each element of the wrapped set with its return value serving as the value for the CSS property. The this property for each function invocation will be set to the element being evaluated.
    Returns
        The wrapped set.
    2.4.2 css(properties)
        Sets the CSS properties specified as keys in the passed object to their associated values for all matched elements
    Parameters
        properties (Object) Specifies an object whose properties are copied as CSS properties to all elements in the wrapped set
    Returns
        The wrapped set
    2.4.3 css(name)
        Retrieves the computed value of the CSS property specified by name for the first element in the wrapped set
    Parameters
        name (String) Specifies the name of a CSS property whose computed value is to be returned
    Returns
        The wrapped set

2.5 width and height
    2.5.1 width(value)
    height(value)
        Sets the width or height of all elements in the matched set
    Parameters
        value (Number) The value to be set in pixels
    Returns
        The wrapped set
    2.5.2 width()
    height()
        Retrieves the width or height of the first element of the wrapped set
    Parameters
        none
    Returns
        The computed width or height as a number

2.6 hasClass
    hasClass(name)
        Determines if any element of the matched set possesses the passed class name
    Parameters
        name (String) The class name to be checked
    Returns
        Returns true if any element in the wrapped set possesses the passed class name; false if not

3. 设置DOM元素的内容
3.1 html
    3.1.1 html()
        Obtains the HTML content of the first element in the matched set.
    Parameters
        none
    Returns
        The HTML content of the first matched element. The returned value is identical to accessing the innerHTML property of that element.
    3.1.2 html(text)
        Sets the passed HTML fragment as the content of all matched elements
    Parameters
        text (String) The HTML fragment to be set as the element content
    Returns
        The wrapped set

3.2 text
    3.2.1 text()
        Concatenates all text content of the wrapped elements and returns it as the result of the command
    Parameters
        none
    Returns
        The concatenated string
    3.2.2 text(content)
        Sets the text content of all wrapped elements to the passed value. If the passed text contains angle brackets (< and >), these characters are replaced with their equivalent HTML entities.
    Parameters
        content (String) The text content to be set into the wrapped elements. Any angle bracket characters are escaped as HTML entities.
    Returns
        The wrapped set.

3.3 append, appendTo, prepend(), prependTo(), before(), insertBefore(), after(), insertAfter()
    append(content)
        Appends the passed HTML fragment or elements to the content in all matched elements.
    Parameters
        content (String|Element|Object) A string, element, or wrapped set to append to the elements of the wrapped set. See the following description for details.
    Returns
        The wrapped set.

3.4 wrap
    wrap(wrapper)
        Wraps the elements of the matched set with the passed HTML tags or a clone of the passed element.
    Parameters
        wrapper (String|Element) The opening and closing tags of the element with which to wrap each element of the matched set, or an element to be cloned and server as the wrapper.
    Returns
        The wrapped set.

3.5 wrapAll
    wrapAll(wrapper)
        Wraps the elements of the matched set, as a unit, with the passed HTML tags or a clone of the passed element.
    Parameters
        wrapper (String|Element) The opening and closing tags of the element with which to wrap each element of the matched set, or an element to be cloned and server as the wrapper.
    Returns
        The wrapped set

3.6 wrapInner
    wrapInner(wrapper)
        Wraps the contents, to include text nodes , elements of the matched set with the passed HTML tags or a clone of the passed element.
    Parameters
        wrapper (String|Element) The opening and closing tags of the element with which to wrap each element of the matched set, or an element to be cloned and server as the wrapper.
    Returns
        The wrapped set

3.7 remove
    remove()
        Removes all elements in the wrapped set from the page DOM
    Parameters
        none
    Returns
        The wrapped set

3.8 empty
    empty()
        Removes the content of all DOM elements in the matched set
    Parameters
        none
    Returns
        The wrapped set

3.9 clone
    clone(copyHandlers)
        Creates copies of the elements in the wrapped set and returns a new wrapped set that contains them. The elements and any children are copied. Event handlers are optionally copied depending upon the setting of the copyHandlers parameter.
    Parameters
        copyHandlers (Boolean) If true, event handlers are copied. If false, or omitted, handlers are not copied.
    Returns
        The newly created wrapped set.

4 处理DOM的表单元素
4.1 val
    4.1.1 val()
        Returns the value property of the first element in the matched set. When the element is a multi-select element, the returned value is an array of all selections.
    Parameters
        none
    Returns
        The fetched value or values.
    4.1.2 val(value)
        Sets the passed value as the value of all matched form elements
    Parameters
        value (String) A string that’s set as the value property of each form element in the wrapped set
    Returns
        The wrapped set
    4.1.3 val(values)
        Causes any check boxes, radio buttons, or options of <select> elements in the wrapped set to become checked or selected if their values match any of the values passed in the values array.
    Parameters
        values (Array) An array of values that will be used to determine which elements are to be checked or selected.
    Returns
        The wrapped set.

来自:Manning.jQuery.in.Action.Feb.2008.pdf
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载