javascript - 两个复选框都被选中

标签 javascript php html

我今天完成了标记工作,然后开始编写代码。所以我们来这里是我的标记代码。

<form action="" id='createchar'>
        <div id="wrapper">

            <!-- Main -->
                <section id="main">
                    <header>
                        <h1>Create New Character</h1>
                        <input type="text" style="margin-top: 10px; width: 1000px;" name="username" placeholder="პერსონაჟის სახელი"/>
                        <input type="checkbox" value="1" id="checkboxFourInput" name="male"/>
                        <label for="checkboxFourInput" style="margin-left: 9px;">კაცი</label>
                        <input type="checkbox" value="2" id="checkboxFourInput2" name="female"/>
                        <label for="checkboxFourInput2" style="margin-right: 810px;margin-top: 15px;">ქალი</label>
                        <input type="text" style="margin-top: 10px; width: 1000px;" name="explainmg" placeholder="განმარტეთ METAGAMING-ი"/>
                        <input type="text" style="margin-top: 10px; width: 1000px;" name="explainpg" placeholder="განმარტეთ POWERGAMING-ი"/>
                        <textarea rows="10" cols="10" name="charbio" placeholder="დაწერეთ თქვენი პერსონაჟის ბიოგრაფი" style="margin-top: 10px; width: 1000px;"></textarea>
                    </header>
                </section>

            <!-- Footer -->
                <footer id="footer">
                    <ul class="copyright">
                        <li>&copy; <a href="http://ls-rp.ge">LS-RP.GE</a></li><li>Design</li>
                    </ul>
                </footer>

        </div>
    </form>

我有这个问题。两个复选框都被选中,但我想避免它。我怎样才能做到?

最佳答案

基本上你应该为此使用 radio :

<form action="" id='createchar'>
        <div id="wrapper">

            <!-- Main -->
                <section id="main">
                    <header>
                        <h1>Create New Character</h1>
                        <input type="text" style="margin-top: 10px; width: 1000px;" name="username" placeholder="პერსონაჟის სახელი"/>
                        <input type="radio" value="1" id="checkboxFourInput" name="gender" value="male" />
                        <label for="checkboxFourInput" style="margin-left: 9px;">კაცი</label>
                        <input type="radio" value="2" id="checkboxFourInput2" name="gender" value="female"/>
                        <label for="checkboxFourInput2" style="margin-right: 810px;margin-top: 15px;">ქალი</label>
                        <input type="text" style="margin-top: 10px; width: 1000px;" name="explainmg" placeholder="განმარტეთ METAGAMING-ი"/>
                        <input type="text" style="margin-top: 10px; width: 1000px;" name="explainpg" placeholder="განმარტეთ POWERGAMING-ი"/>
                        <textarea rows="10" cols="10" name="charbio" placeholder="დაწერეთ თქვენი პერსონაჟის ბიოგრაფი" style="margin-top: 10px; width: 1000px;"></textarea>
                    </header>
                </section>

            <!-- Footer -->
                <footer id="footer">
                    <ul class="copyright">
                        <li>&copy; <a href="http://ls-rp.ge">LS-RP.GE</a></li><li>Design</li>
                    </ul>
                </footer>

        </div>
    </form>

Note that when use radio you should have all relevant elements have the same value in the name attribute.

关于javascript - 两个复选框都被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46228757/

相关文章:

javascript - 如何将文本框值作为 href 的一部分传递

html - Bootstrap 下拉菜单子(monad)菜单不起作用

javascript - JQuery 更改事件不是每次都会触发

javascript - 调整窗口大小后重新计算图像映射

javascript - 插入不匹配列名的对象

javascript - 在浏览器窗口/选项卡关闭上打开自定义弹出窗口

php - MySQL 中的双引号 (Laravel Seeder)

javascript - JQuery POST数据到php,直接到php,数据在php中不再存在

php - 如何创建带有可覆盖变量的 PayPal 按钮

javascript - 将 HTML 数据属性中的值提取到 jQuery 插件选项数组中