简体   繁体   English

Angular JS:基于单选按钮选择显示div

[英]Angular JS : show div based on radio button selection

 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script> <div ng-app=""> <div class="radio_toggle"> <label class="hubilo"> <input type="radio" name="registration_options" checked="checked"> <span>Company ABC</span></label> <label class="other" > <input type="radio" name="registration_options" ng-click="show_other=true"> <span>Other</span></label> <label class="none" > <input type="radio" name="registration_options" ng-click="display=false"> <span>None</span></label> </div> <div class="form-group" ng-show="show_other"> <label class="col-md-2 col-sm-2 col-xs-12 control-label"></label> <div class="col-md-10 col-sm-10 col-xs-12"> <form role="form"> <div class="form-group set_margin_0 set_padding_0"> <label>Button</label> <input class="form-control" placeholder="Enter Button Name" type="text"> </div> </form> </div> </div> <div class="form-group"> <label class="col-md-2 col-sm-2 col-xs-12 control-label"></label> <div class="col-md-10 col-sm-10 col-xs-12"> <span>Link</span> <input class="form-control" placeholder="http://" type="text"> </div> </div> </div> 

clicking on company radio button only link will be opened and clicking on other radio button button text box and link , both should be opened. 单击“ 公司”单选按钮仅链接将打开,然后单击其他单选按钮按钮文本框和链接,两者均应打开。 and clicking on none. 然后单击无。 both of them should hide. 他们两个都应该躲起来。

Any help would be great. 任何帮助都会很棒。

Thank You. 谢谢。

 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script> <div ng-app=""> <div class="radio_toggle"> <label class="hubilo"> <input type="radio" name="registration_options" checked="checked" ng-click="option='company'" ng-init="option='company'"> <span>Company ABC</span></label> <label class="other" > <input type="radio" name="registration_options" ng-click="option='other'"> <span>Other</span></label> <label class="none" > <input type="radio" name="registration_options" ng-click="option='none'"> <span>None</span></label> </div> <div class="form-group" ng-show="option ==='other'"> <label class="col-md-2 col-sm-2 col-xs-12 control-label"></label> <div class="col-md-10 col-sm-10 col-xs-12"> <form role="form"> <div class="form-group set_margin_0 set_padding_0"> <label>Button</label> <input class="form-control" placeholder="Enter Button Name" type="text"> </div> </form> </div> </div> <div class="form-group" ng-show="option ==='other' || option === 'company'"> <label class="col-md-2 col-sm-2 col-xs-12 control-label"></label> <div class="col-md-10 col-sm-10 col-xs-12"> <span>Link</span> <input class="form-control" placeholder="http://" type="text"> </div> </div> </div> 

Following changes are done. 完成以下更改。

1) Clicked item is saved in 'option' variable. 1)单击的项目保存在“选项”变量中。

2) Show the form field based on data in 'option' variable. 2)根据“选项”变量中的数据显示表单字段。

It is seems confusing because you want to start with the URL box shown so you need to use a mix of ng-show and ng-hide then override them on click. 这似乎令人困惑,因为您想从显示的URL框开始,因此需要混合使用ng-showng-hide然后在单击时覆盖它们。

 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script> <div ng-app=""> <div class="radio_toggle"> <label class="hubilo"><input type="radio" name="registration_options" checked="checked" ng-click="show_url=false;show_other=false"><span>Company ABC</span></label> <label class="other"><input type="radio" name="registration_options" ng-click="show_other=true;show_url=false"><span>Other</span></label> <label class="none"><input type="radio" name="registration_options" ng-click="show_other=false;show_url=true"><span>None</span></label> </div> <div class="form-group" ng-show="show_other"> <label class="col-md-2 col-sm-2 col-xs-12 control-label"></label> <div class="col-md-10 col-sm-10 col-xs-12"> <form role="form"> <div class="form-group set_margin_0 set_padding_0"> <label>Button</label> <input class="form-control" placeholder="Enter Button Name" type="text"> </div> </form> </div> </div> <div class="form-group" ng-hide="show_url"> <label class="col-md-2 col-sm-2 col-xs-12 control-label"></label> <div class="col-md-10 col-sm-10 col-xs-12"> <span>Link</span> <input class="form-control" placeholder="http://" type="text"> </div> </div> </div> 

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

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