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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:47:28  来源:igfitidea点击:

input checkbox checked by default?

htmlcsslaravelcheckbox

提问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 checkboxchecked 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 使其默认勾选