-1

جافا سكربت : لماذا if checked لا يعمل ؟

ما الخطأ عندما تحاول التحقق ما إذا كان radio Button محدد أم لا ؟

input id='px10' type='radio' name='fontSize'>10px>

 <script type="text/javascript">
        var px10 = document.querySelector('#px10');
        if (px10.checked)
        alert('d');
    </script>

التعليق السابق

هناك عدة طريق ابسطها هو التالي

<input type="radio" name="gender" value="male" onClick="getGender(this)">
<input type="radio" name="gender" value="female" onClick="getGender(this)">
<script>
    function getGender(elm){
         alert(elm.value)
    }
</script>