gpt4 book ai didi

javascript - 如何在AngularJs中同时绑定(bind)单选按钮和复选框?

转载 作者:行者123 更新时间:2023-11-28 18:16:37 25 4
gpt4 key购买 nike

我已经尝试过,如果我选中该复选框,那么单选按钮也会被选中。当我选中复选框时一切顺利。

但是,如果我选择单选按钮绑定(bind)过程不会发生。即,如果我单击单选按钮,则必须选中该复选框。

我不知道该怎么做?

这里放置了代码。

<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Learn It HTML Template</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app="sampleApp">
<div ng-controller="sampleController">
Are you going for party tonight: <input type="checkbox" ng-checked="checked" ng-model="checked">
<br/> <br/>
You should go, Complete this example and rest examples you can learn tomorrow :), So click on the check box above:
<br/> <br/>
<input id="checkSlave" type="radio" ng-checked="checked">Yeah :)

</div>
<script>
var app = angular.module("sampleApp", []);
app.controller('sampleController', ['$scope', function ($scope) {
$scope.checked= 0;
}]);
</script>
</body>
</html>

有人可以帮忙吗?

最佳答案

试试这个

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
<script>
var app = angular.module("sampleApp", []);
app.controller('sampleController', ['$scope', function ($scope) {


}]);
</script>
<body ng-app="sampleApp">
<div ng-controller="sampleController" ng-init="checked='false'">
Are you going for party tonight: <input type="checkbox" ng-checked="checked" ng-click="checked = !checked">
<br/> <br/>
You should go, Complete this example and rest examples you can learn tomorrow :), So click on the check box above:
<br/> <br/>
<input id="checkSlave" type="radio" ng-checked="checked" ng-click="checked = !checked">Yeah :)
</div>

关于javascript - 如何在AngularJs中同时绑定(bind)单选按钮和复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40671149/

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