• <tfoot id='ki579'></tfoot>
    <i id='ki579'><tr id='ki579'><dt id='ki579'><q id='ki579'><span id='ki579'><b id='ki579'><form id='ki579'><ins id='ki579'></ins><ul id='ki579'></ul><sub id='ki579'></sub></form><legend id='ki579'></legend><bdo id='ki579'><pre id='ki579'><center id='ki579'></center></pre></bdo></b><th id='ki579'></th></span></q></dt></tr></i><div id='ki579'><tfoot id='ki579'></tfoot><dl id='ki579'><fieldset id='ki579'></fieldset></dl></div>

      1. <legend id='ki579'><style id='ki579'><dir id='ki579'><q id='ki579'></q></dir></style></legend>

        <small id='ki579'></small><noframes id='ki579'>

          <bdo id='ki579'></bdo><ul id='ki579'></ul>

      2. 使用 javascript 检查单选按钮

        Check a radio button with javascript(使用 javascript 检查单选按钮)

        <legend id='GOlTq'><style id='GOlTq'><dir id='GOlTq'><q id='GOlTq'></q></dir></style></legend>
        <tfoot id='GOlTq'></tfoot>

        <small id='GOlTq'></small><noframes id='GOlTq'>

            <i id='GOlTq'><tr id='GOlTq'><dt id='GOlTq'><q id='GOlTq'><span id='GOlTq'><b id='GOlTq'><form id='GOlTq'><ins id='GOlTq'></ins><ul id='GOlTq'></ul><sub id='GOlTq'></sub></form><legend id='GOlTq'></legend><bdo id='GOlTq'><pre id='GOlTq'><center id='GOlTq'></center></pre></bdo></b><th id='GOlTq'></th></span></q></dt></tr></i><div id='GOlTq'><tfoot id='GOlTq'></tfoot><dl id='GOlTq'><fieldset id='GOlTq'></fieldset></dl></div>
                • <bdo id='GOlTq'></bdo><ul id='GOlTq'></ul>
                    <tbody id='GOlTq'></tbody>
                  本文介绍了使用 javascript 检查单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  由于某种原因,我似乎无法弄清楚这一点.

                  For some reason, I can't seem to figure this out.

                  我的 html 中有一些单选按钮可以切换类别:

                  I have some radio buttons in my html which toggles categories:

                  <input type="radio" name="main-categories" id="_1234" value="1234" /> // All
                  <input type="radio" name="main-categories" id="_2345" value="2345" /> // Certain category
                  <input type="radio" name="main-categories" id="_3456" value="3456" /> // Certain category
                  <input type="radio" name="main-categories" id="_4567" value="4567" /> // Certain category
                  

                  用户可以选择任何他/她想要的,但是当某个事件触发时,我想设置 1234 设置为选中单选按钮,因为这是默认选中单选按钮.

                  The user can select whichever he/she wants, but when an certain event triggers, I want to set 1234 to be set checked radio button, because this is the default checked radio button.

                  我已经尝试过这个版本(有和没有 jQuery):

                  I have tried versions of this (with and without jQuery):

                  document.getElementById('#_1234').checked = true;

                  但它似乎没有更新.我需要它明显更新,以便用户可以看到它.有人可以帮忙吗?

                  But it doesn't seem to update. I need it to visibly update so the user can see it. Can anybody help?

                  我只是累了,忽略了 #,感谢您指出它和 $.prop().

                  I'm just tired and overlooked the #, thanks for pointing it out, that and $.prop().

                  推荐答案

                  不要将 CSS/JQuery 语法(# 表示标识符)与原生 JS 混合.

                  Do not mix CSS/JQuery syntax (# for identifier) with native JS.

                  原生 JS 解决方案:

                  document.getElementById("_1234").checked = true;

                  jQuery 解决方案:

                  $("#_1234").prop("checked", true);

                  这篇关于使用 javascript 检查单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  keeping radio buttons checked after form submit(表单提交后保持选中单选按钮)
                  Styling radio button - not work in IE and Firefox(样式单选按钮 - 在 IE 和 Firefox 中不起作用)
                  Bootstrap radio button quot;checkedquot; flag(Bootstrap 单选按钮“已选中旗帜)
                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)

                        <bdo id='lpYfO'></bdo><ul id='lpYfO'></ul>
                            <tbody id='lpYfO'></tbody>

                        • <tfoot id='lpYfO'></tfoot>
                          <i id='lpYfO'><tr id='lpYfO'><dt id='lpYfO'><q id='lpYfO'><span id='lpYfO'><b id='lpYfO'><form id='lpYfO'><ins id='lpYfO'></ins><ul id='lpYfO'></ul><sub id='lpYfO'></sub></form><legend id='lpYfO'></legend><bdo id='lpYfO'><pre id='lpYfO'><center id='lpYfO'></center></pre></bdo></b><th id='lpYfO'></th></span></q></dt></tr></i><div id='lpYfO'><tfoot id='lpYfO'></tfoot><dl id='lpYfO'><fieldset id='lpYfO'></fieldset></dl></div>
                          <legend id='lpYfO'><style id='lpYfO'><dir id='lpYfO'><q id='lpYfO'></q></dir></style></legend>

                            <small id='lpYfO'></small><noframes id='lpYfO'>