【问题标题】:How to Disable input field when radio button will choose using angular.js当单选按钮选择使用angular.js时如何禁用输入字段
【发布时间】:2016-04-04 10:39:48
【问题描述】:

我需要一个help.i需要禁用我的一些输入字段当单选按钮选择。我解释下面的代码。

<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Unit Cost Price :</span>
<input type="text" name="discount" id="ucp" class="form-control" placeholder="Add unit cost price" ng-model="unit_cost_price" ng-keypress="clearField('ucp');" ng-readonly="ucpread" ng-disabled="ucpdis">
</div>
<div class="input-group bmargindiv1 col-md-12" >
<input type="radio" name="favoriteColors" ng-model="isChecked.new">Add new stock
<input type="radio" name="favoriteColors" ng-model="isChecked.old">Update stock 
</div>

在上面的代码中,我得到Update stock 默认被选中。我需要当用户选择Update stock 时,上面的Unit Cost Price 字段将被禁用/只读,当用户选择Add new stock 时,它将被启用。请帮帮我。

【问题讨论】:

  • 试试ng-disabled="isChecked.new"
  • 我测试了,但它没有来。

标签: javascript angularjs radio-button


【解决方案1】:

为单选按钮赋值并将其与禁用\启用文本进行比较

 <input type="radio" ng-model="isChecked" name="favoriteColors" value="true" />Add new stock
 <input type="radio" ng-model="isChecked" name="favoriteColors" value="false" />Update stock

 <input type="text" ng-disabled="isChecked=='false'">

检查这个提琴手:http://jsfiddle.net/ryf2h49p/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 2012-09-11
    • 2021-09-10
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    相关资源
    最近更新 更多