Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   переключение radio (https://javascript.ru/forum/dom-window/17812-pereklyuchenie-radio.html)

zionko 03.06.2011 16:59

переключение radio
 
switchMethod: function(method,type){
	this.changeVisible(this.currentMethod, true);
        if(type == "true") {
		if (this.currentMethod && $('payment_form_'+this.currentMethod)) {
            this.changeVisible(this.currentMethod, true);
        }
        if ($('payment_form_'+method)){
            this.changeVisible(method, false);
            $('payment_form_'+method).fire('payment-method:switched', {method_code : method});
        } else {
            //Event fix for payment methods without form like "Check / Money order"
            document.body.fire('payment-method:switched', {method_code : method});
        }
		}

        this.currentMethod = method;
    },

    changeVisible: function(method, mode) {
        var block = 'payment_form_' + method;
        [block + '_before', block, block + '_after'].each(function(el) {
            element = $(el);
            if (element) {
                element.style.display = (mode) ? 'none' : '';
                element.select('input', 'select', 'textarea').each(function(field) {
                    field.disabled = mode;
                });
            }
        });
    },


сам код

в зависимости от выбранного radio , открывает нужный <div>

все отлично работает пока не столкнулся с тем чтобы один был открыт ( checked = checked )

<input value="1" type="radio" name="test" onclick="payment.switchMethod('test1')" class="radio" checked = checked autocomplete="off">
<input value="2" type="radio" name="test" onclick="payment.switchMethod('test2')" class="radio" autocomplete="off">

но див таким образом не открывается пока я не-нажму на radio кнопку , как можно сделать так чтобы он был сразу открыт ?

zionko 09.06.2011 11:05

идей совсем нет ?

ksa 09.06.2011 11:37

Цитата:

Сообщение от zionko
как можно сделать так чтобы он был сразу открыт ?

Таки сразу его и открыть...

zionko 09.06.2011 16:13

ну да если он checked = checked то чтобы был сразу открытым , и не надо было повторно нажимать чтобы javasript сработал


Часовой пояс GMT +3, время: 16:24.