http.post成功时不会触发input元素的Click事件

时间:2015-03-23 14:49:44

标签: javascript jquery angularjs

HTML:

<input type="file" id="mypic" accept="image/*" capture="camera" onchange="angular.element(this).scope().uploadFile(this.files)" />
<div style="float:right;">
    <button class="btn" ng-click="yesClick('/paLabel/mainLabel=')">yes</button>
</div>

角:

$scope.yesClick = function (viewName) {
    var input = document.querySelector('input[type=file]');
    $log.log("input: " + input);
    input.click();

    $log.log(viewName);
    $location.path(viewName);
}

上面的示例工作正常,并且引发了input元素的click事件。 但是当我在http.post-success函数中尝试相同时,它会失败!?

$scope.yesClick = function (viewName) {
    CheckAmount($scope.amount, viewName);
}

function CheckAmount(val,viewName) {

    var endpoint = Model.getServerAdress() + "CheckAmount";
    var req = {
        method: 'POST',
        url: endpoint,
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: 'amount=' + $scope.amount
    };

    $http(req)
        .success(function (data) {
            $scope.amountDB = makeJsonString(data, $log);

            if ($scope.amountDB == val)
            {
                var input = document.querySelector('input[type=file]');
                $log.log("input: " + input);
                input.click();

                $location.path(viewName);
            }
            else {
                ...
            }

        })
        .error(function (data) {
            $log.log("ERROR" + data);
        });
}

在这种情况下,点击事件不会被触发! 问题是什么?在这两种情况下,日志都显示document.querySelector创建的输入对象是HTMLInputElement

0 个答案:

没有答案