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>
满意答案
看到这个小提琴: 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)
在带有单选按钮和“其他”文本字段的HTML表单中,无法理解单选按钮的值(In my HTML form with radio buttons and an 'other' text field the values of the radio buttons are not understood)
为什么在键入文本输入时无法选择单选按钮(Why can't a radio button stay selected when typing in text input)
Textinput字段禁用单选按钮(Textinput field disables radio buttons)
单选按钮和一个输入字段(Radio Button and an Input field)
如何使用单选按钮将下拉菜单绑定到收音机?(How to bind radio a drop down menu with radio buttons?)
使用单选按钮(jQuery)禁用/启用文本字段(Disable/enable text field with radio button (jQuery))
angularjs使用下拉和单选按钮绑定输入文本字段(angularjs bind input text field with drop down and radio buttons)
使用滑块angularjs绑定单选按钮(bind radio buttons with slider angularjs)
Reagent-Forms单选按钮显示为文本字段(Reagent-Forms radio buttons displaying as text fields)
相关文章
更多Solr4.7---Field、CopyField、DynamicField
jquery1.4.4的radio选中项
AngularJs视频教程
solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias
HTML5 Drag and Drop【HTML5教程 - 第六篇】
Angularjs 中文视频教程
input 框的自动提示框 错位
Solr Document [null] missing required field: id 的原因
Solr官方文档系列——Text Analysis
最新问答
更多Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)
故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)
我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)
TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)
返回嵌套元素的索引(Return index of nested element)
在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!