gpt4 book ai didi

javascript - 数据仅显示输入是否被触摸 - AngularJs

转载 作者:行者123 更新时间:2023-12-03 07:28:17 24 4
gpt4 key购买 nike

我正在制作一个简单的程序,其中输入数据只有在触摸一次输入时才必须显示。但是,我无法获得预期的结果,因为跨度中没有显示任何内容(而且控制台中没有错误)。有人可以帮我吗?

HTML:

<html>
<head>
<!-- Script Files -->
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.js"></script>

</head>
<body ng-app="myApp" ng-controller="myCtrl">
<input type="text" name="person" ng-model="name"/><span ng-show="person.$touched">{{name}}</span>
<script>
//module declaration
var app = angular.module('myApp',[]);
//controller declaration
app.controller('myCtrl', function($scope) {
$scope.name = "Enter Name";
});
</script>
</body>
</html>

Note:

I cannot use any form in this page. I have to calculate ng-show event with ng-touched, ng-untouched, ng-prestine - but without wrapping up in any form.

最佳答案

如果您只担心表单标签,您可以使用 ng-form 属性。

<html>
<head>
<!-- Script Files -->
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.js"> </script>

</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div ng-form name="myForm" id="myForm">
<input type="text" name="person" ng-model="name"/>
<span> {{myForm.person.$touched}}</span>
</div>
<script>
//module declaration
var app = angular.module('myApp',[]);
//controller declaration
app.controller('myCtrl', function($scope) {
$scope.name = "Enter Name";
});
</script>
</body>
</html>

关于javascript - 数据仅显示输入是否被触摸 - AngularJs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35914114/

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