简体   繁体   English

单选按钮无法选择

[英]Radio button not able to select

My Script.js file has below code我的Script.js文件有以下代码

$scope.typeValue = ["120","123"];

My HTML has below code我的 HTML 有以下代码

<div class="radio">
    <label>
        <!-- ng-change="RadioChange('type')"-->
        <input type="radio" name="type0" ng-value="true"/> {{typeValue[0]}}
    </label>
    <label>
        <input type="radio" name="type1" ng-value="false"/> {{typeValue[1]}}
    </label>
</div>

I cannot select radio button on my page我无法选择页面上的单选按钮

页

I've ran this code locally and observed that radio button is selecting properly but unable to deselect once selected and also both are able to select.我在本地运行了这段代码,并观察到单选按钮选择正确,但一旦选择就无法取消选择,而且两者都可以选择。

Assuming your requirement is to select only one a time.假设您的要求是一次只选择一个。 If this is the scenario want to implement then the way to do is choose same name for the both radio inputs as:如果这是要实现的场景,那么要做的方法是为两个无线电输入选择相同的名称:

<div class="radio">
<label>
 <!-- ng-change="RadioChange('type')"-->
<input type="radio" name="type" ng-value="true"/> {{typeValue[0]}}
 </label>
 <label>
<input type="radio" name="type" ng-value="false"/> {{typeValue[1]}}
</label>
</div>

If my assumption is wrong, requesting to elaborate your question properly if possible with example!如果我的假设是错误的,请尽可能以示例正确阐述您的问题!

At last hope, this is your requirement.最后希望,这是你的要求。 Try this code... and let me know!试试这个代码......让我知道!

<!DOCTYPE html>
<html>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<body>
    <div ng-app="myApp" ng-controller="myCtrl">
      <div class="radio">
        <label>
        <!-- ng-change="RadioChange('type')"-->
          <input type="radio" name="type0" ng-value="true"/> {{typeValue[0]}}
        </label>
        <label>
        <input type="radio" name="type0" ng-value="false"/> {{typeValue[1]}}
        </label>
      </div>
    </div>

<script>
  var app = angular.module("myApp",[]);
    app.controller("myCtrl", function($scope) {
    $scope.typeValue = ["120","123"];
   });
</script>

</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM