JavaScript - замена onchange в input radio checked - вопрос №2379935

<input type=«radio» name=«shop_delivery_condition_id» value=«5» id=«shop_delivery_condition_id» onchange="$.getOnestepPaymentSystemList('{/shop/url}cart/', $(this).closest('form'))" checked=«checked» /> — не работает, так как onchange — обработчик события, но события не будет так как input radio и уже checked, на что можно заменить onchange, чтобы getOnestepPaymentSystemList отработал сразу при загрузки страницы?

Ответы

<html>
    <head>
        <title> </title>
    </head>
    <body>
        <input type=«radio» name=«shop_delivery_condition_id» value=«5» id=«shop_delivery_condition_id» checked=«checked»
       
        <script>
            var inputRadio = document.getElementById('shop_delivery_condition_id');
           
            window.onload = inputRadio.onchange = function() {
                if (inputRadio.checked) {
                    alert('checked == true');
                   
                    $.getOnestepPaymentSystemList(
                        '{/shop/url}cart/',
                        $(this).closest('form')
                    );
                }
            };
        </script>
    </body>
</html>
22.03.17

Глеб Черняк

Сейчас на сайте
Читать ответы

Олег Николаевич

Читать ответы
Посмотреть всех экспертов из раздела Технологии > Компьют. безопасность
Пользуйтесь нашим приложением Доступно на Google Play Загрузите в App Store