gpt4 book ai didi

javascript - javascript 在服务器上运行时未定义

转载 作者:行者123 更新时间:2023-11-29 22:12:55 26 4
gpt4 key购买 nike

这让我难住了以下代码:

<!DOCTYPE html>
<html ng-app>
<head>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script>
function ctrl($scope){
$scope.submit = function(e){
var elem = angular.element(e.srcElement);
alert($(elem.parent()).html());
//alert ('first name ' + person.first + ' last name ' + person.last);
};
}
</script>
</head>
<body>
<div ng-controller="ctrl">
First: <input name="first" value="will" />
Last: <input name="last" value = "kriski" />
<input type="submit" name="submit" ng-click="submit($event)"/>
</div>
</body>
</html>

在 jsfiddle 和 plunker 中正常工作(单击提交但在警报中显示 HTML)。

但是当我在本地和我的个人服务器上运行相同的代码时,警报显示为“未定义”

这些都有效: http://jsfiddle.net/sjmcpherso/yQs8z/193/ http://plnkr.co/qaqymNFQIe3ziyj7AKXa

我的个人服务器上的相同粘贴代码不 http://sjmcpherson.com/testing/test.html

很迷茫

最佳答案

试试这个代码

<script type = "text/javascript">
$(document).ready(function(e) {
function ctrl($scope)
{
$scope.submit = function(e){
var elem = angular.element(e.srcElement);
alert($(elem.parent()).html());
//alert ('first name ' + person.first + ' last name ' + person.last);
};
}
});
</script>

或写function ctrl($scope) { //Your code goes here }就在关闭 </body> 之前

关于javascript - javascript 在服务器上运行时未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17079713/

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