当javascript在服务器上运行时未定义
Undefined when javascript runs on servers
这让我对下面的代码感到困惑:
<!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>
或者在关闭</body>
之前写function ctrl($scope) { //Your code goes here }
Doh实际上我意识到这个错误只发生在Firefox而不是Chrome,并且涉及到与Firefox不兼容的srcElement这篇文章解释了一个修复我如何制作事件。srcElement在Firefox中工作,它是什么意思?
相关文章:
- 从JSON API结果迭代时未定义
- 在setInterval函数之前声明时未定义对象
- 变量在运行时未定义,但在使用调试器时定义
- $routeParams在传递到新视图时未定义&控制器
- 通过Ajax发送时未定义的变量
- Javascript - 加载函数运行时未定义的变量
- Angularjs-NgTable在重新加载时未定义
- 使用AMD时未定义淘汰组件视图模型
- 引用错误:在尝试使用ajax发送数据时未定义
- vendors.js:未捕获类型错误:无法读取属性'应用'使用webpack时未定义的
- 为什么在Node.js上使用jQuery时未定义$.ajax
- 对象在循环中运行时未定义,但在按顺序执行时未定义
- appView 在运行时未定义在主干中
- 为什么我的类在运行时未定义.Javascript 模块模式
- JavaScript 运行时错误:“$”在尝试运行示例代码时未定义
- 运行时未定义Typescript模块
- 代码日志记录在$.get请求中运行时未定义,但在页面上运行时工作正常
- 当javascript在服务器上运行时未定义
- JavaScript运行时错误:'变量'在检查是否未定义时未定义
- physijs -> physijs_worker.js -> 错误:“运行时未定义”