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://stackoverflow.com/questions/39871375
最满意答案
看到这个小提琴: 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)[2022-05-14]
我想你应该在这两个单选按钮中使用具有不同值的相同变量。 然后,您应该根据用户输入设置“Rma”或“Delivery”。 I think you should use same variable with diff ... -
设置无线电输入的value属性。 该值将发布到您的服务器。 除非您指定,否则该值将为“on”。 Sigma-Aldrich [2022-05-14]为您创建了一个解决问题的拉取请求。 https://github.com/jansensan/test-angularjs-text-input-in-radio-group/pull/1 正如jw56578已经说过,通过在输入中添加一个值来覆盖vm.appModel.amount属性,这意味着不再检查单选按钮。 我重构了您的代码,因此它包含一个包含属性数量和类型的付款对象。 对于手动付款,现在将设置payment.type(这将控制单选按钮),金额将存储在payment.amount中。 Created ...
-
使用jQuery,您可以执行以下操作(当用户单击文本字段时,使用类radio禁用单选按钮): $("#location").click(function(){ $(".radio").prop("disabled", true); }); 现在,如果您需要启用单选按钮,如果用户单击外部(或以另一种方式离开文本字段)文本字段,您可以更改上面代码中的click以blur ,如下所示: $("#location").blur(function(){ $(".radio").prop("disab ...
-
单选按钮和一个输入字段(Radio Button and an Input field)[2021-09-26]
我举了个例子,这是你想要的吗? 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 = ''; } ... -
一种方法是使用相同的ng-model ,这意味着你想要考虑无线电的相应值应该是什么,这将是数组中的对象 var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.colors = [ {model : "Red"}, {model : "Green"}, {model : "Blue"}, {model ...
-
根据您的网站html完全更改。 这应该工作: $(document).ready( function(){ $('#casodhoda,#casprihoda').prop('disabled',true); $('input[type=radio][name=radioknof]').click( function(){ $('#casodhoda,#casprihoda').prop('disabled',true).val(''); $(this).next('span').c ...
-
angularjs使用下拉和单选按钮绑定输入文本字段(angularjs bind input text field with drop down and radio buttons)[2022-06-20]
看到这个小提琴: https : //jsfiddle.net/U3pVM/27636/Selection
脚本: $scope.change = function(a){ $scope.selectFruit = $scope.fruits[a]; } 当您在文本框中输入一个数字(索引)时,它将选择相应的项目。 S ... -
我认为你应该对收音机使用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 to b ...
-
字段不是正确的输入元素属性。 [: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 [:input { ...