gpt4 book ai didi

javascript - 获取只读文本框中的值

转载 作者:行者123 更新时间:2023-11-28 18:13:38 24 4
gpt4 key购买 nike

我有一个文本框,其中包含不可编辑的硬编码值。我需要帮助检索它并在单击按钮时显示。如何验证下拉列表以使其成为必需的?如何在此下拉列表中显示所选值,我尝试使用 ng-model 但它不起作用。

<div class="col-sm-6">
<input class="form-control" id="focusedInput" type="text" value="El Dix" readonly>
</div>

对于下拉菜单,代码如下:-

<select ng-model="createCall_Urgency" class="form-control" >
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
<option value="Major">Major</option>
</select>

最佳答案

1) I need help with retrieving it and display on button click

HTML

<button id="getValue" ng-click="getValue()">Get Value</button>
<input class="form-control" id="focusedInput" type="text" ng-model="focusedInput" readonly>

JS

$scope.focusedInput='El Dix';
$scope.getValue=function(){
alert($scope.focusedInput);
}

2)How can I validate dropdown to make it required?

您需要使用required属性。

<select ng-model="createCall_Urgency" class="form-control" required>
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
<option value="Major">Major</option>
</select>

3)How can I display the selected value on this dropdown ?

我建议您创建一个对象数组并使用 ngOptions 指令。

类似这样的事情:

var app = angular.module('eApp', []);
app.controller('ArrayController', ['$scope', function($scope) {

$scope.myOptions = [{
"id": 'Low',
"text": 'Low'
}, {
"id": 'Medium',
"text": 'Medium'
},
{
"id": 'High',
"text": 'High'
},{
"id": 'Major',
"text": 'Major'
}];
$scope.createCall_Urgency = $scope.myOptions[0];
}]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
<body ng-app="eApp">
<div ng-controller="ArrayController">
<select ng-model="createCall_Urgency" class="form-control" data-ng-options="options as options.text for options in myOptions">
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
<option value="Major">Major</option>
</select>
{{createCall_Urgency.text}}
</div>

</body>

关于javascript - 获取只读文本框中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41118056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com