Mootools常用方法扩展(五)

Posted on March 03, 2009 by Fdream

继续Mootools的扩展,适用于Mootools 1.1及1.2,这次在Element扩展了两个非常简单的方法,一个用来获取或者设置一个元素的innerHTML(这个是模仿jQuery里面的html()方法),还一个方法是把一个表单对象转成hash对象,用得比较少一点。

方法:html

说明:当参数不为空时,设置一个元素的innerHTML,当参数为空时,返回当前元素的innerHTML。

Element.implement({
    html: function(s) {
        ///<summary>
        /// 获取元素的HTML内容或者设置元素的HTML内容
        ///</summary>
        ///<param name="s" type="String">参数为空时,获取HTML内容;参数为字符串时,设置HTML的内容</param>
        ///<returns type="String" />
        if (s === undefined) {
            return this.get('html');
        }
        else {
            this.set('html', s + '');
            return s;
        }
    }
});

方法:toHash

说明:把一个表单对象转换成为一个Hash对象,方便验证处理。

Element.implement({
    toHash: function() {
        ///<summary>
        /// 把一个表单转成Hash对象
        ///</summary>
        ///<returns type="Hash" />
        return this.toQueryString().toHash();
    }
});

分享 |
Categories:
Ajax Web
Tags:
, ,
Comments:
Leave a comment
Views:
1,849 Views

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>