【发布时间】:2019-04-15 16:43:15
【问题描述】:
我有一个 select 下拉列表,其中填充了 angularjs ng-repeat 指令。我希望 div 仅在选择某个选项时显示。
代码如下:
<select type="text"
class="form-control"
ng-model="vm.request.requestType"
name="requestType" id="requestType"
placeholder=""
required>
<option selected></option>
<option value="test">test</option>
<option ng-repeat="requestType in vm.requestTypes">{{requestType}}</option>
</select>
<script>
$(function() {
$("#requestType").change(function () {
if ($("#test").is(":selected")) {
$("#continueCheckbox").show();
} else {
$("#continueCheckbox").hide();
}
}).trigger('change');
});
</script>
<div id="continueCheckbox">
<input type="checkbox"
name="continueCheckbox"
value="continueCheckbox">
Check this box to continue, and to confirm that you have read the
Documentation
</div>
“测试”选项仅用于测试功能是否有效。目前,无论选择什么,复选框都会显示,并且永远不会消失。
【问题讨论】:
-
角度项目是你的吗?如果是这样,请不要使用 jQuery。请参阅下面的答案(和 cmets),了解使用 Angular 完成您想要的各种选项:
ng-if、ng-hide、ng-show、ng-class和/或ng-style都是做你想做的事情的潜在方法想要 Angular。 -
您知道如何将数据从数据库中获取到您的 Angular 应用程序吗?
标签: javascript jquery html angularjs