gpt4 book ai didi

javascript - 在输入字段中输入值后如何显示跨度? Angular JS

转载 作者:行者123 更新时间:2023-12-02 14:12:42 25 4
gpt4 key购买 nike

我在 Controller 中定义了一个作用域变量,最初作用域变量的值为空。

我将 ng-model 绑定(bind)到输入字段,并将 ng-show 添加到需要显示的范围,一旦在输入字段中输入了值。

当我在输入字段中输入值时,跨度未显示。

代码:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-ng-form-production</title>


<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>


<script type="text/javascript">
angular.element(document.getElementsByTagName('head')).append(angular.element('<base href="' + window.location.pathname + '" />'));
</script>
</head>
<body ng-app="formExample">
<script>
angular.module('formExample', [])
.controller('FormController', ['$scope', function($scope) {
$scope.userType = '';
}]);
</script>
<form name="myForm" ng-controller="FormController" class="my-form">
userType: <input name="input" ng-model="userType">
<span ng-show="myForm.input.length>0">show me!</span><br>
</form>
</body>
</html>

这是演示链接:

Demo Plunker

最佳答案

您需要检查范围变量userType的长度,它应该是,

<span ng-show="userType.length>0">show me!</span><br>

DEMO APP

关于javascript - 在输入字段中输入值后如何显示跨度? Angular JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39381542/

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