0

我试图通过强制用户在文本输入中键入单词“DELETE”来启用删除按钮。下面的代码可以工作,但是它区分大小写,这意味着如果有人例如键入“删除”,它将不起作用。

谁能建议我如何更改下面的代码以使其不区分大小写?

 <div ng-app="">
  <div ng-controller="test">
  <label>Type the word DELETE below to confirm</label>
  <input type="text" placeholder="TYPE DELETE" ng-model="deletetext" /> <br />
  <button class="btn btn-danger" ng-disabled="deletetext != 'DELETE'">DELETE</button>
  </div>
</div>

谢谢

4

2 回答 2

1

Thilo 建议使用 deletetext.toUpperCase() != 'DELETE' 解决了这个问题。这个更正的代码现在看起来像这样

<div ng-app="">
  <div ng-controller="test">
  <label>Type the word DELETE below to confirm</label>
  <input type="text" placeholder="TYPE DELETE" ng-model="deletetext" /> <br />
  <button class="btn btn-danger" ng-disabled="deletetext.toUpperCase() != 'DELETE'>DELETE</button>
  </div>
</div>
于 2013-04-14T15:10:00.610 回答
1

deletetext.toUpperCase() != 'DELETE'作品。您还可以添加 $watchdeletetext并将其强制为大写。IMO 的可用性更好。

$scope.$watch('deletetext', function(newValue, oldValue){
    $scope.deletetext = newValue.toUpperCase();
});

这是完整的例子:http: //jsfiddle.net/GLCAT/

于 2013-04-14T15:11:19.823 回答