[英]Radio-button act like checkbox
Here is my code: 这是我的代码:
HTML: HTML:
<label><input type="radio" name="radio"> Checkbox 1</label>
<label><input type="radio" name="radio"> Checkbox 2</label>
JavaScript: JavaScript:
$(document).ready(function(){
$(":radio").behaveLikeCheckbox();
});
I got the code from here . 我从这里得到了代码。 My problem is that I can't make it work. 我的问题是我无法使其正常运行。
Can someone help? 有人可以帮忙吗?
You have to include jQuery and the behaveLikeCheckbox plugin to make this work. 您必须包括jQuery和behaviorLikeCheckbox插件才能使此项工作。 Here is an updated fiddle: http://jsfiddle.net/mq8Zq/174/ 这是更新的小提琴: http : //jsfiddle.net/mq8Zq/174/
So in your HTML document: 因此,在您的HTML文档中:
<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>
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 查看页面的源代码,似乎您必须包括jquery和行为的扩展
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.radio.checkbox.behavior.js"></script>
You need to include some JS files : JQuery, and the plugin for the checkbox. 您需要包括一些JS文件:JQuery和复选框的插件。 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>
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". 当您给他们加上相同的名字时,只有一个被“选中”。
使type =“ checkbox”和名称相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.