Jquery学习小计

实时监听输入框值变化

首先创建Jquery.fn扩展

jQuery.fn.extend({
    inputChange: function(callback){
        if($.support.leadingWhitespace){
        //if($.browser.msie){
            this.bind('propertychange', function(e){
            if(e.originalEvent.propertyName == 'value'){
                $(this).keyup();
            }
        });
        this.bind('keyup', callback);
        }else{
        this.bind('input', callback);
        }
        return( this );
    }
});

调用方法:

$('.input').inputChange(function(){
    console.log($(this).val());
});

 

获取select值

$("#selectID option:selected").text()

 

posted @ 2013-08-23 14:25  Younger  阅读(241)  评论(0编辑  收藏  举报