gpt4 book ai didi

html - 如何使选中的属性与中间选项一起使用?

转载 作者:搜寻专家 更新时间:2023-10-31 08:52:00 25 4
gpt4 key购买 nike

我有一组用于日、月和年的单选按钮。

<label>
<input type="radio" ng-model="IsDays" name="timeunit" > Period in days
<input type="radio" ng-model="IsMonths" ng-checked="true" name="timeunit"> Period in months
<input type="radio" ng-model="IsYears" name="timeunit" > Period in years
</label>


我已经读到,尽管将选中的属性置于中间选项中,但如果单选按钮具有相同的名称,组中的最后一个按钮将被选中属性值

我在 checkedng-checked="true" 场景中都试过了。

有没有一种简单的方法可以覆盖此行为并允许默认检查中间选项()?

更新:解决了我自己的问题。请参阅下面的答案。

最佳答案

张贴答案以供将来引用:

Just checked 只有在默认情况下需要选中最后一个单选按钮选项时才会起作用。

我们需要为中间选项提供 checked="checked"。在这种情况下,仅选中 将不起作用。

<label>
<input type="radio" ng-model="IsDays" name="timeunit" > Period in days
<input type="radio" ng-model="IsMonths" checked="checked" name="timeunit"> Period in months
<input type="radio" ng-model="IsYears" name="timeunit" > Period in years

奇怪:)

更新:即使在清除浏览器 cookie 后这也不起作用。在查看了一些 AngularJS 文档之后,我得到了以下解决方案。

        <label>
<input type="radio" ng-model="timeunit" value="days">
Period in days
</label><br />
<label>
<input type="radio" ng-model="timeunit" value="months">
Period in months
</label><br />
<label>
<input type="radio" ng-model="timeunit" value="years">
Period in years
</label><br />

我们必须为所有三个单选按钮的 ng-model 设置相同的值,而不是设置相同的名称属性,以使它们作为一个组起作用。

要设置默认,我们可以在js文件中设置如下

 function ($scope) {

$scope.timeunit = "months"; //Default set to months

//Other code
}

关于html - 如何使选中的属性与中间选项一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40520904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com