设置单选按钮以查看课程

时间:2014-09-21 14:30:28

标签: jquery css3 checkbox radio-button

我有一个问题就是动态设置收音机或复选框以进行检查。 所以我有一个jquery函数应该这样做...

像这样:

return this.each(function() {
    var $this = $(this);
    var $span = $('<span/>');
    var name = $this.attr('name');

    $span.addClass('panel_'+ ($this.is(':checkbox') ? 'check' : 'radio')).attr('name', name);
    $this.is(':checked') && $span.addClass('checked'); // init
    $span.insertAfter($this);

    $this.parent('label').addClass('panel_label')
    .attr('onclick', ''); // Fix clicking label in iOS
    // hide by shifting left
    $this.css({ position: 'absolute', left: '-9999px' });

    // Events
    $this.on({
        change: function() {
            if (options.debug) {window.console.debug('meRadioCheck:  change: ', [$this])};
            $('input:radio[name=' + name + ']').parent().removeClass('active');

            if ($this.is(':radio')) {
                $this.parent().siblings('label')
                .find('.panel_radio[name="'+ name +'"]').removeClass('checked');
            }
            $span.toggleClass('checked', $this.is(':checked'));
            $this.parent().toggleClass('active', $this.is(':checked'));
        },
        focus: function() { $span.addClass('focus'); },
        blur: function() { $span.removeClass('focus'); }
    });

    if (options.checked) {
        if (options.debug) {window.console.debug('meRadioCheck:  checked: ' + options.checked, [$this])};

        if ($this.is(':radio')) {
            $this.prop('checked', true);
            //$this.meRadioCheck();

        } else if ($this.is(':checkbox')) {
        }
    }
});

我想这样称呼它......

$('input[type=checkbox], input[type=radio]').meRadioCheck();
$('#Pan_Hide').meRadioCheck({'checked': true});     
$('#Pan_Droppable').meRadioCheck({'checked': true});

如果你点击一个单选按钮或复选框,它就可以了。 所以我希望你能帮助我。这是我的尝试... http://jsfiddle.net/Tabes/x5rhoj4v/

0 个答案:

没有答案