【问题标题】:Display div or input box, when drop down value selected as Others显示 div 或输入框,当下拉值选择为其他时
【发布时间】:2016-10-05 11:22:10
【问题描述】:

Plnkr 代码供审核:https://plnkr.co/edit/vWR7kK9MQw4nyciRt1Bj?p=preview

一旦下拉值被选为Others,如何显示div或输入框?

HTML

<div class="form-group fields col-sm-2 col-xs-4">
    <label>EDUCATION QUALIFICATION *</label>
    <select name="education" class="form-control1 drop" required ng-model="model.education" placeholder="select">
        <option value='' disabled selected>Select</option>
        <option value="male">10th</option>
        <option value="female">12th</option>
        <option value="male">Graduate</option>
        <option value="male">Post Graduate</option>
        <option value="male">Ph.d</option>
        <option value="other">Others</option>
    </select>
</div>

<div class="form-group fields col-sm-2 col-xs-4 floatField" ng-if =" model.education=Others;displayDiv = true">  
    <label>OTHERS</label>
    <input type="text" name="othereducation" class="form-control1" autocomplete="off" ng-model="model.othereducation"/>
</div> 

【问题讨论】:

  • 为什么要手动编写选项标签而不是使用 ng-options?
  • 仅供练习。
  • 您想根据选择框的值显示文本框或 div 吗?
  • 您可以使用模型(model.education)来显示/隐藏输入框。你不是吗?
  • @ram1993 我试过给 ng-show ="model.education==others" 仍然没有显示。

标签: html angularjs html-select angular-ngmodel


【解决方案1】:

您可以使用 Angular 内置指令 ng-show/ng-hide 来显示或隐藏内容。

所以当你在选择框中选择值'other'时,你可以添加下面的sn-p来显示所需的内容。

<div ng-show="model.education==='other'">
    DIV/input you want to show
</div>

演示: JSBin

【讨论】:

  • 你能在jsbin中快速复制问题吗?
  • 对我来说它正在工作。通过演示查看更新的答案
  • 检查您在浏览器控制台中遇到的错误
  • plnkr.co/edit/vWR7kK9MQw4nyciRt1Bj?p=preview 没有错误。但是你可以在这里看到代码
  • @NicoletaWilskon 您需要在 plnkr 中进行很多更改。你没有包括 AnagularJS,指定 ng-app 以及你认为你是如何运行 Angular 应用程序的?
【解决方案2】:

这是工作的link

试试下面的代码

代码

<div  ng-if="model.education==='other'">
         <label >OTHERS</label>
             <input type="text" name="othereducation" class="form-control1" autocomplete="off" ng-model="model.othereducation"/>

          </div>

【讨论】:

猜你喜欢
  • 2013-09-16
  • 2012-07-03
  • 1970-01-01
  • 1970-01-01
  • 2018-04-04
  • 2016-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多