【问题标题】:Submitting form data after changing values of hidden fields更改隐藏字段的值后提交表单数据
【发布时间】:2013-10-23 13:15:45
【问题描述】:

我有一个简单的 html 表单:

<form id="formD" action="/somewhere" method="POST">
  <input type="hidden" name="i[value]" ng-model="i.value" value={{i.value}}
  <button type="button" ng-click="changevalue()) Change Value

使用表单控制器:

function myFormController($scope) 
{
  $scope.saveAsDraft = function(){
    $scope.i.value="true";
    console.log($scope);
    document.getElementById("formD").submit();
  };
}

在检查控制台日志时,value$scope 内发生变化,但提交后,i.value 始终为空!我在哪里做错了?

我采取的另一种方法是将输入字段设为文本:

<input type='text' name="i[value]" id="something" 
       ng-model='i.value' style="display:none;">

请帮忙。如何在提交表单数据之前更改此隐藏字段的值?

【问题讨论】:

  • 为什么要用逗号分隔属性?这是不正确的。你应该只用空格分隔它们。
  • 这些逗号在 HTML 中是字面意思吗?他们不应该在那里!
  • Tch Tch Tch,那些逗号在那里是因为我最初用玉写了它们,为了清楚起见,我在这里写了 HTML,忘记在这里删除逗号,将编辑答案。这些逗号不是我问题的答案

标签: javascript forms angularjs


【解决方案1】:

您正在用逗号分隔属性。这是不正确的。它们应用空格分隔,如下例所示:

<input type="text" name="i[value]" id="something" 
       ng-model="i.value" style="display:none;">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多