如何从角度提交此表单?

时间:2013-08-24 15:20:30

标签: angularjs angularjs-scope

此示例中的顶部按钮在IE 8中不起作用。底部按钮可以。 我需要添加/更改此示例,以便顶部按钮也可以在IE8中工作?

<html ng-app>
<head>
    <script>
         function form_controller($scope) {
            $scope.my_submit = function() {
                alert("Using angular");

                document.my_form.method = document.my_form.method_x.value;
                document.my_form.action = document.my_form.action_x.value;

                alert(document.my_form.method);
                alert(document.my_form.action);
                alert("submitting");

                document.my_form.submit();
            }
        }
        function my_submit() {

            document.my_form.method = document.my_form.method_x.value;
            document.my_form.action = document.my_form.action_x.value;

            alert(document.my_form.method);
            alert(document.my_form.action);
            alert("Using normal form : submitting");

            document.my_form.submit();
            return(false);
        }
    </script>
</head>
<body>
    <form ng-controller="form_controller" name="my_form">
        <input type="button" value="testing" ng-click="my_submit()"/><br/>
        <input type="button" value="testing" onclick="my_submit()"/><br/>
        <input type="hidden" name="method_x" value="post"/>
        <input type="hidden" name="action_x" value="http://www.yahoo.com"/>
    </form>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
</body>

3 个答案:

答案 0 :(得分:0)

 

<script>
     function form_controller($scope) {
          $scope.method_x="11";
           $scope.action_x="ewwe";


        $scope.my_submit = function() {
           $scope.method_x="dfdf";
           $scope.action_x="dfsdsddf";


        }
    }
    function my_submit() {

        document.my_form.method = document.my_form.method_x.value;
        document.my_form.action = document.my_form.action_x.value;

        alert(document.my_form.method);
        alert(document.my_form.action);
        alert("Using normal form : submitting");

        document.my_form.submit();
        return(false);
    }
</script> </head> <body>
<form ng-controller="form_controller" name="my_form">
    {{method_x}}<br>
    {{action_x}}<br>

    <input type="button" value="testing" ng-click="my_submit()"/><br/>
    <input type="button" value="testing" onclick="my_submit()"/><br/>
    <input type="hidden" ng-model="method_x" name="method_x" value="post"/>
    <input  type="hidden" ng-model="action_x" name="action_x" value="http://www.yahoo.com"/>
</form> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
     

答案 1 :(得分:0)

试试这段代码;

<html ng-app>
<head>
    <script>
         function form_controller($scope) {
            $scope.my_submit = function() {
                alert("Using angular");

                document.my_form.method = document.my_form.method_x.value;
                document.my_form.action = document.my_form.action_x.value;

                alert(document.my_form.method);
                alert(document.my_form.action);
                alert("submitting");

                document.my_form.submit();
            }
        }
        function my_submit() {

            document.my_form.method = document.my_form.method_x.value;
            document.my_form.action = document.my_form.action_x.value;

            alert(document.my_form.method);
            alert(document.my_form.action);
            alert("Using normal form : submitting");

            document.my_form.submit();
            return(false);
        }
    </script>
</head>
<body>
    <form ng-controller="form_controller" name="my_form" ng-click="my_submit()">
        <input type="submit" value="testing"/><br/>
        <input type="button" value="testing" onclick="my_submit()"/><br/>
        <input type="hidden" name="method_x" value="post"/>
        <input type="hidden" name="action_x" value="http://www.yahoo.com"/>
    </form>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
</body>

答案 2 :(得分:0)

我解决了它 - 我们需要顶部的doc类型声明,以及将IE置于兼容模式的元标记。我也把class =“ng-app”但我不知道是否需要。

<!DOCTYPE html>
<html lang="en" class="ng-app" ng-app> 
  <head>
  <meta http-equiv="X-UA-Compatible" content="IE=8">
  ... rest of page