基本上和 https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_onkeyup一樣
但由于某種原因,我收到了這個錯誤。
HTML
<nb-card>
<nb-card-header>
Enter your name:
</nb-card-header>
<nb-card-body>
<input type="text" id="fname" onkeyup="myFunction()">
</nb-card-body>
<script>
function myFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</nb-card>

沒有星云庫的相同錯誤:HTML
<html>
<body>
Enter your name:
<input type="text" id="fname" onkeyup="myFunction()">
<script>
function myFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</body>
</html>
有誰知道為什么?謝謝。
我嘗試了許多其他堆疊溢位解決方案,但它們不起作用。我希望不使用 JQuery。這應該有效,但沒有。我遵循其他 W3 School 示例并得到相同的錯誤。
uj5u.com熱心網友回復:
您的代碼似乎在這里作業正常。有什么問題?
<nb-card>
<nb-card-header>
Enter your name:
</nb-card-header>
<nb-card-body>
<input type="text" id="fname" onkeyup="myFunction()">
</nb-card-body>
<script>
function myFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</nb-card>
uj5u.com熱心網友回復:
這不是在 AngularJS 中編碼的方式。利用平臺的內置功能——比如使用ng-click、 ng-model和ng-keyup
在這種情況下,我認為解決方案就像使用 CSS 類強制大寫一樣簡單,但我仍然希望這會有所幫助。
angular.module('myApp', [])
.controller('myCtrl', ['$scope', '$http', function($scope, $http) {
$scope.fname = "";
$scope.myFunction = function() {
console.log($scope.fname)
}
}]);
.ucase {
text-transform: uppercase;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<nb-card>
<nb-card-header>
Enter your name:
</nb-card-header>
<nb-card-body>
<input type="text" ng-model="fname" class='ucase' ng-keyup="myFunction()">
</nb-card-body>
</nb-card>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/452290.html
