What are jQuery valHooks?

后端 未结 3 1872
日久生厌
日久生厌 2021-02-04 00:46

After reading about valHooks in a jQuery defect and more recently seen in a fiddle I searched the jQuery documentation and Google but I can\'t find anything other t

3条回答
  •  误落风尘
    2021-02-04 01:13

    I did a little writeup with a simple example here.

    $.valHooks['myedit'] = {
        get : function(el) {
            return $(el).html();
        },
        set : function(el, val)
        {
            $(el).html(val);
        }
    };
    
    $.fn.myedit = function()
    {
        this.each(function() {
            this.type = 'myedit';
        });
        return this;
    }
    
    $('#edit').myedit().val(' Hi there!');
    $('#value').html('The value is : ' + $('#edit').val());
    

提交回复
热议问题