Javascript 选中单选按钮ng默认情况下不显示div,仅在单击时起作用
我对使用Angular js进行web开发还不熟悉。我试图使用类在div中显示和隐藏文本框。我有两个单选按钮“是”和“否”。因此,我试图在单击“是”时显示包含文本框的div,在单击“否”时隐藏该div。Javascript 选中单选按钮ng默认情况下不显示div,仅在单击时起作用,javascript,angularjs,radio,angularjs-ng-init,angularjs-ng-checked,Javascript,Angularjs,Radio,Angularjs Ng Init,Angularjs Ng Checked,我对使用Angular js进行web开发还不熟悉。我试图使用类在div中显示和隐藏文本框。我有两个单选按钮“是”和“否”。因此,我试图在单击“是”时显示包含文本框的div,在单击“否”时隐藏该div。 现在,我尝试只使用ng类和ng模型,而不使用ng show/ng hide 当我使用ng checked=“true”在默认情况下单击一个单选按钮(说是)时,为什么不显示div,而只在再次单击按钮时显示div。ng检查是否适用于ng类。 是 不 不要使用ng复选框它只会选择一个单选框,但不会更
现在,我尝试只使用ng类和ng模型,而不使用ng show/ng hide 当我使用ng checked=“true”在默认情况下单击一个单选按钮(说是)时,为什么不显示div,而只在再次单击按钮时显示div。ng检查是否适用于ng类。
是
不
不要使用ng复选框
它只会选择一个单选框,但不会更新ng型号值。使用ng init
并设置model的值,而不是执行ng checked
工作HTML
<div ng-app>
<div class="radioToggle1">
<div class="col-xs-12 form-group" id="request_same" ng-init="request_same='Yes'" >
<p>Yes or no</p>
<label class="ui-radio checkbox-inline">
<input type="radio" name="toggle1" data-check="1" value="Yes" ng-model="request_same" /> <span> Yes </span>
</label>
<label class="ui-radio checkbox-inline">
<input type="radio" name="toggle1" data-check="2" value="No" ng-model="request_same" /> <span> No </span>
</label>
</div>
<div data-show="1" ng-class="{ active : request_same == 'Yes' }" class="hide-div">
<div class="col-xs-12 col-md-12 borderTop">
<h5> <strong> Vendor Details </strong> </h5>
<input type="text" />
</div>
</div>
</div>
<div data-show="2"></div>
</div>
是还是不是
对
不
供应商详细信息
刚刚添加了hide div
class以默认隐藏div。然后ng class
将根据条件决定是否显示元素
希望这能对你有所帮助。谢谢。你的小提琴坏了
<div ng-app>
<div class="radioToggle1">
<div class="col-xs-12 form-group" id="request_same" ng-init="request_same='Yes'" >
<p>Yes or no</p>
<label class="ui-radio checkbox-inline">
<input type="radio" name="toggle1" data-check="1" value="Yes" ng-model="request_same" /> <span> Yes </span>
</label>
<label class="ui-radio checkbox-inline">
<input type="radio" name="toggle1" data-check="2" value="No" ng-model="request_same" /> <span> No </span>
</label>
</div>
<div data-show="1" ng-class="{ active : request_same == 'Yes' }" class="hide-div">
<div class="col-xs-12 col-md-12 borderTop">
<h5> <strong> Vendor Details </strong> </h5>
<input type="text" />
</div>
</div>
</div>
<div data-show="2"></div>
</div>