Radio-button act like checkbox

旧城冷巷雨未停 提交于 2019-12-13 04:32:25

问题


Here is my code:

HTML:

<label><input type="radio" name="radio"> Checkbox 1</label>
<label><input type="radio" name="radio"> Checkbox 2</label>

JavaScript:

$(document).ready(function(){
    $(":radio").behaveLikeCheckbox();
});

JSFiddle.

I got the code from here. My problem is that I can't make it work.

Can someone help?


回答1:


You have to include jQuery and the behaveLikeCheckbox plugin to make this work. Here is an updated fiddle: http://jsfiddle.net/mq8Zq/174/

So in your HTML document:

<label><input type="radio" name="radio"> Checkbox 1</label>
<label><input type="radio" name="radio"> Checkbox 2</label>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="relative/path/to/plugin/or/cdn"></script>
<script>
  $(document).ready(function(){
     $(":radio").behaveLikeCheckbox();
  });
</script>



回答2:


sadly, that example page doesn't explain anything...

looking at the source code of the page, it seems that you have to include jquery and the extension for the behavior

 <script type="text/javascript" src="jquery.js"></script>
 <script type="text/javascript" src="jquery.radio.checkbox.behavior.js"></script> 



回答3:


You need to include some JS files : JQuery, and the plugin for the checkbox. Like this :

<!doctype html>
<html>
    <head>
        <script type="text/javascript" src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
        <script type="text/javascript" src="http://www.digitss.com/jquery/jquery.radio.checkbox.behavior.js"></script>
    </head>
    <body>
        <label><input type="radio" name="radio"> Checkbox 1</label>
        <label><input type="radio" name="radio"> Checkbox 2</label>

        <script>
            $(document).ready(function(){
                $(":radio").behaveLikeCheckbox();
            });
        </script>
    </body>
</html>



回答4:


The only thing you have to do is put a different "name" to your Radios. When you put the same name to them, only one gets "selected".




回答5:


Make type="checkbox" and name Same



来源:https://stackoverflow.com/questions/18080905/radio-button-act-like-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!