angularjs使用下拉和单选按钮绑定输入文本字段(angularjs bind input text field with drop down and radio buttons)

我有这个单选按钮和动态同步的下拉菜单。 我试图包括一个输入框(选择域),用户可以在其中输入他们的选择作为一个数字,例如,如果用户在输入框中键入3,下拉菜单和单选按钮也应该动态改变为橙色这种情况下,如果用户键入2到香蕉等。 而且,我正在尝试动态列出答案字段中的选定水果。 谢谢您的帮助

 var app = angular.module('App', []);
app.controller('aCtrl', function($scope) {
    $scope.fruits = [
        {name : "apple"},
        {name : "banana"},
        {name : "orange"},
        {name : "melon"}
    ];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<div ng-app="App" ng-controller="aCtrl">

<p>choose a fruit</p>

<select ng-model="selectFruit" ng-options="x.name for x in fruits">
</select>
<input name='a' type="radio" ng-model="selectFruit" ng-value="fruits[0]"> apple
<input name='a' type="radio" ng-model="selectFruit"  ng-value="fruits[1]" > banana
<input name='a' type="radio" ng-model="selectFruit"  ng-value="fruits[2]"> orange
<input name='a' type="radio" ng-model="selectFruit"  ng-value="fruits[3]"> melon

 <p>Selection <input type="text" ng-model="selectFruit" /></p>

 <p>Answer</p>
<div ng-switch="selectFruit">
<div ng-switch-when="apple">
<h1>apple</h1>
  </div>

</div>


i have this radio buttons and drop down menu that are synchronized dynamically. Im trying to include an input box (the selection field) where the user can type their choice as a number, for example if the user types 3 in the input box, the drop down menu and radio buttons should dynamically change as well to orange in this case and if the user types 2 to banana and so on. And also, I'm trying to list the selected fruit in the answer field dynamically. thanks for the help

 var app = angular.module('App', []);
app.controller('aCtrl', function($scope) {
    $scope.fruits = [
        {name : "apple"},
        {name : "banana"},
        {name : "orange"},
        {name : "melon"}
    ];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<div ng-app="App" ng-controller="aCtrl">

<p>choose a fruit</p>

<select ng-model="selectFruit" ng-options="x.name for x in fruits">
</select>
<input name='a' type="radio" ng-model="selectFruit" ng-value="fruits[0]"> apple
<input name='a' type="radio" ng-model="selectFruit"  ng-value="fruits[1]" > banana
<input name='a' type="radio" ng-model="selectFruit"  ng-value="fruits[2]"> orange
<input name='a' type="radio" ng-model="selectFruit"  ng-value="fruits[3]"> melon

 <p>Selection <input type="text" ng-model="selectFruit" /></p>

 <p>Answer</p>
<div ng-switch="selectFruit">
<div ng-switch-when="apple">
<h1>apple</h1>
  </div>

</div>

2022-06-20 09:06

满意答案

看到这个小提琴: https//jsfiddle.net/U3pVM/27636/

<p>Selection <input type="text" ng-model="selectFruit" ng-change="change(selectFruit)" /></p >

脚本:

$scope.change = function(a){
      $scope.selectFruit = $scope.fruits[a];
    }

当您在文本框中输入一个数字(索引)时,它将选择相应的项目。


See this fiddle : https://jsfiddle.net/U3pVM/27636/

<p>Selection <input type="text" ng-model="selectFruit" ng-change="change(selectFruit)" /></p>

Script:

$scope.change = function(a){
      $scope.selectFruit = $scope.fruits[a];
    }

When you enter a number(index) in textbox it will selects the corresponding item.

相关问答

更多

Angularjs单选按钮(Angularjs radio buttons)

我想你应该在这两个单选按钮中使用具有不同值的相同变量。 <input ng-model="searchBy" value="Rma" type="radio" name="search-type"> <input ng-model="searchBy" value="Delivery" type="radio" name="search-type"> 然后,您应该根据用户输入设置“Rma”或“Delivery”。 I think you should use same variable with...

在带有单选按钮和“其他”文本字段的HTML表单中,无法理解单选按钮的值(In my HTML form with radio buttons and an 'other' text field the values of the radio buttons are not understood)

设置无线电输入的value属性。 该值将发布到您的服务器。 除非您指定,否则该值将为“on”。 <input type="radio" name="q3_supplier" id="q3" onchange="disableTxt()" checked="checked" value='Sigma-Aldrich'/>Sigma-Aldrich <input type="radio" name="q3_supplier" id="q3" onchange="disableTxt()" value...

为什么在键入文本输入时无法选择单选按钮(Why can't a radio button stay selected when typing in text input)

为您创建了一个解决问题的拉取请求。 https://github.com/jansensan/test-angularjs-text-input-in-radio-group/pull/1 正如jw56578已经说过,通过在输入中添加一个值来覆盖vm.appModel.amount属性,这意味着不再检查单选按钮。 我重构了您的代码,因此它包含一个包含属性数量和类型的付款对象。 对于手动付款,现在将设置payment.type(这将控制单选按钮),金额将存储在payment.amount中。 Cre...

Textinput字段禁用单选按钮(Textinput field disables radio buttons)

使用jQuery,您可以执行以下操作(当用户单击文本字段时,使用类radio禁用单选按钮): $("#location").click(function(){ $(".radio").prop("disabled", true); }); 现在,如果您需要启用单选按钮,如果用户单击外部(或以另一种方式离开文本字段)文本字段,您可以更改上面代码中的click以blur ,如下所示: $("#location").blur(function(){ $(".radio").prop("...

单选按钮和一个输入字段(Radio Button and an Input field)

我举了个例子,这是你想要的吗? http://www.jsfiddle.net/T7gE7/ var temp = ''; function disableTxt() { var field = document.getElementById("other"); if(field.value != '') { temp = field.value; } field.style.display = "none"; field.value = '...

如何使用单选按钮将下拉菜单绑定到收音机?(How to bind radio a drop down menu with radio buttons?)

一种方法是使用相同的ng-model ,这意味着你想要考虑无线电的相应值应该是什么,这将是数组中的对象 var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.colors = [ {model : "Red"}, {model : "Green"}, {model : "Blue"}, {...

使用单选按钮(jQuery)禁用/启用文本字段(Disable/enable text field with radio button (jQuery))

根据您的网站html完全更改。 这应该工作: $(document).ready( function(){ $('#casodhoda,#casprihoda').prop('disabled',true); $('input[type=radio][name=radioknof]').click( function(){ $('#casodhoda,#casprihoda').prop('disabled',true).val(''); $(this).next('spa...

angularjs使用下拉和单选按钮绑定输入文本字段(angularjs bind input text field with drop down and radio buttons)

看到这个小提琴: https : //jsfiddle.net/U3pVM/27636/ <p>Selection <input type="text" ng-model="selectFruit" ng-change="change(selectFruit)" /></p > 脚本: $scope.change = function(a){ $scope.selectFruit = $scope.fruits[a]; } 当您在文本框中输入一个数字(索引)时,它将选择相应的...

使用滑块angularjs绑定单选按钮(bind radio buttons with slider angularjs)

我认为你应该对收音机使用ng-change ,并根据你的滑块重新初始化。 不要忘记指定单选按钮的ng-value 。 "use strict"; // Creates the "backend" logical support for appMyExample var myModule = angular.module("appMyExample", []); // define a function to create a new slider at locID (expected...

Reagent-Forms单选按钮显示为文本字段(Reagent-Forms radio buttons displaying as text fields)

字段不是正确的输入元素属性。 [:input {:field :radio}] (option :name)]])) 应该是 [:input {:type :radio}] (option :name)]])) Field is not a correct input element attribute. [:input {:field :radio}] (option :name)]])) Should probably be [:in...

相关文章

更多

Solr4.7---Field、CopyField、DynamicField

Field: Field就是一个字段,定义一个Field很简单: 基本上属性也和FieldType类似 ...

jquery1.4.4的radio选中项

var updkbval=$(&quot;input[name=sex][@checked]&quot ...

AngularJs视频教程

|----5-2:前端自动化测试(2).mp4 |----5-1:前端自动化测试(1).mp4 |-- ...

solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias

在solr中 添加新的索引词语时,报如标题所示错误,指定是插入的字段没有在solr索引字段里 可以修改 ...

HTML5 Drag and Drop【HTML5教程 - 第六篇】

拖放/拖拽(drag and drop)这是个非常普遍的功能。你可以抓住一个对象,并且拖动到你想放置的 ...

Angularjs 中文视频教程

Angularjs 中文视频教程 029 - 自定义指令 controller 等属性_高清.mp4 ...

input 框的自动提示框 错位

所有输入框都是在iframe下面的。浏览器自带的 input自动提示框 在input框下方 40px左 ...

Solr Document [null] missing required field: id 的原因

在solr建立索引的时候,如果你提交的doc中没有 id 这个Field,结果Solr在建立索引时候出 ...

Solr官方文档系列——Text Analysis

Text fields are typically indexed by breaking the t ...

最新问答

更多

Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)

你得到IndexError的原因是你的输入文件显然不是完全用制表符分隔的。 这就是为什么当您尝试访问它时, splits[1]没有任何内容。 您的代码可以使用一些重构。 首先,你正在重复使用if -checks,这是不必要的。 这只是将cds0到7个字符,这可能不是你想要的。 我将以下内容放在一起,以演示如何重构您的代码,使其变得更加pythonic和干燥。 我无法保证它能够与您的数据集一起使用,但我希望它可以帮助您了解如何以不同的方式执行操作。 to_sort = [] # W

故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)

我不认为你可以链接一个特定的细节披露按钮瓦特/赛格。 我的故事板是非常程序化的B / C我使用了很多定制CGRect等。 所以我倾向于使用这样的东西: -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"ViewControllerIdentifer"

我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)

TestComplete不支持Gherkin功能文件。 但是,TestComplete具有SDK,因此可以自己为此创建扩展。 TestComplete does not support Gherkin feature files. However, TestComplete has SDK so it is possible to create an extension for this by yourself.

TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)

我没有做过这样的事情,但看看我认为可以看出错误的例子。 试试这个代码: static class Program { static void Main() { var tcpclient = new TcpClient("remote.example.com", 443); var tcpstream = tcpclient.GetStream(); var sslstream = new SslStream(tcpstream,

返回嵌套元素的索引(Return index of nested element)

您需要获取父li元素的索引。 否则,您将获得列表项内锚点的索引,该索引始终为零。 $(this.parentNode).index(); You need to get the index of the parent li element. Otherwise you are getting the index of the anchor inside the list item, which will always be zero. $(this.parentNode).index();

在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)

您需要多次迭代列表,我认为没有办法解决这个问题。 毕竟,在开始更改元素(第二遍)之前,首先必须确定不同元素的数量(第一遍)。 但是请注意,由于对index的重复调用而not in列表中具有O(n),因此可能具有最多O(n ^ 2)的不同元素的数量。 或者,您可以使用dict而不是value_map的list 。 字典比列表具有更快的查找速度,因此,复杂性应该确实在O(n)的数量级上。 您可以使用(1)字典理解来确定旧值到新值的映射,以及(2)用于创建更新子项的列表理解。 value_map =

Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)

选项1 你可以改变这一行: app.use( express.static(__dirname + '/puplic')); //my public folder. 至 app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder 选项2 我假设你在公共文件夹中有一个js文件夹,然后你需要更改你的HTML代码:

使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)

对于计时器值,请在服务器端本身每秒更新本地计时器。 每当有任何用户进来时,给他这个值以及计时器的总值。 然后客户端将根据dandavis评论在本地启动自己的计时器,但在服务器端保留一些间隔,如15或10秒,服务器将广播当前计时器值,以便客户端相应地进行同步。 简而言之,服务器将每隔10(n:你决定)秒后广播,但它将在本地每秒更新定时器变量。 每当客户端进入时,它将获得总计时器值和当前计时器值。 广播当前出价的休息功能可以以正常方式完成。 For timer value, keep updatin

如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)

IXmlSerializable也许? 注意我还添加了(对A ): [XmlElement("A", Namespace = "http://www.example.com/namespace")] public TestSoapHeaderTypeValuePair A {...} 代码如下: public class TestSoapHeaderTypeValuePair : IXmlSerializable { private string _type; private