2

这让我难倒了以下代码:

<!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

真的很迷茫

4

2 回答 2

1

Doh 实际上我认为该错误仅发生在 Firefox 而不是 Chrome 中,并且与与 Firefox 不兼容的 srcElement 相关,这篇文章解释了修复如何使 event.srcElement 在 Firefox 中工作,这是什么意思?

于 2013-06-13T09:11:50.340 回答
1

尝试使用此代码

<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>

于 2013-06-13T05:25:51.213 回答