这使我难受以下代码:
<!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中正常工作(单击Submit,但在警报中显示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/