在IE8中测试时,我的Javascript无效

时间:2016-10-08 22:18:10

标签: javascript jquery html css internet-explorer-8

我正在建立一个网站,其中一个要求是IE8兼容。我的页面上有一个简单的表单,并使用单选按钮我正在更改窗体的哪些字段集可见。基本上我给用户一个输入他的名字或号码的选项。我在F12菜单中的IE8兼容模式下在W10上使用IE11,切换不起作用。它适用于其他任何地方,即使在IE9 +中。你知道这可能是什么问题吗?

我的单选按钮都有一个onclick功能,可以在display:none设置一个fieldset,在display:block设置另一个。默认情况下隐藏“header__form__fs_person”。

HTML:

           <form class="header__form" name="form_name">
                <fieldset class="header__form__label_choices">
                    <label class="header__form__label" for="person">Podle jména</label>
                    <input class="header__form__input_radio" type="radio" value="person_on" id="person" name="choice" onclick="hideIc(this)" checked>

                    <span class="header__form__divider">/</span>

                    <label class="header__form__label" for="ic">Podle IČ</label>
                    <input class="header__form__input_radio" type="radio" value="ic_on" id="ic" name="choice" onclick="hidePerson(this)">
                </fieldset>

                <fieldset class="header__form__fs_person">
                    <input class="header__form__input_text" type="text" id="name" placeholder="Jméno" required>

                    <input class="header__form__input_text" type="text" id="lastname" placeholder="Příjmení" required>

                    <input class="header__form__input_text" type="text" id="bday" placeholder="Narozen" onfocus="(this.type='date')" required>
                </fieldset>

                <fieldset class="header__form__fs_ic" disabled>
                    <input class="header__form__input_text" pattern=".{9,}" placeholder="123456789" required>
                </fieldset>

                <label class="header__form__terms" for="terms">Souhlasím s <a class="header__form__terms_a" href="">obchodnimi podmínkami</a></label>
                <input class="header__form__input_checkbox" type="checkbox" id="terms" required>

                <input class="header__form__input_btn" type="submit" value="Ověřit">
            </form>

JS:

<script>
            function hideIc(radio_btn) {
                if (radio_btn.checked) {
                    var ic = document.getElementsByClassName("header__form__fs_ic");
                    var person = document.getElementsByClassName("header__form__fs_person");

                    for (var i=0; i < ic.length; i++) {
                        ic[i].style.display = "none";
                        ic[i].disabled = true;

                        person[i].style.display = "block";
                        person[i].disabled = false;

                    }

                }
            }

            function hidePerson(radio_btn) {
                if (radio_btn.checked) {

                    var ic = document.getElementsByClassName("header__form__fs_ic");
                    var person = document.getElementsByClassName("header__form__fs_person");

                    for (var i=0; i < ic.length; i++) {
                        ic[i].style.display = "block";
                        ic[i].disabled = false;

                        person[i].style.display = "none";
                        person[i].disabled = true;
                    }
                }
            }

        </script>

1 个答案:

答案 0 :(得分:0)

IE8不支持Syntax error: Unexpected token (22:8) 20 | const render = () => ReactDOM.render( 21 | > 22 | {store.getState()}

见这里:http://caniuse.com/#feat=getelementsbyclassname

有一个遍历:

getElementsByClassName()

答案不是我的......我在这里找到了:
javascript document.getElementsByClassName compatibility with IE