Html 默认情况下选中输入复选框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31442898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
input checkbox checked by default?
提问by aladin2222
I have this code:
我有这个代码:
<div class="checkbox">
<label>
<input type="checkbox" data-bind="checked: params.availToStream">
{{ trans('stream::main.onlyAvailToStream') }}
</label>
</div>
I want to have the checkbox
checked by default, I have tried the following but cannot get it to work.
我想checkbox
默认检查,我尝试了以下但无法让它工作。
<input type="checkbox" data-bind="checked: params.availToStream" selected>
<input type="checkbox" data-bind="checked: params.availToStream" checked="checked">
<input type="checkbox" data-bind="checked: params.availToStream" checked>
回答by Adam Buchanan Smith
View my fiddle https://jsfiddle.net/7sud8341/3/this works
查看我的小提琴https://jsfiddle.net/7sud8341/3/这有效
<div class="checkbox">
<label>
<input type="checkbox" data-bind="checked: params.availToStream" checked>
{{ trans('stream::main.onlyAvailToStream') }}
</label>
</div>
回答by Vonfry
http://www.w3school.com.cn/tags/att_input_checked.aspYou can get more info here. If it doesn't work well, you can also use JavaScript to make it checked by default
http://www.w3school.com.cn/tags/att_input_checked.asp您可以在这里获得更多信息。如果效果不好,也可以使用 JavaScript 使其默认勾选