在 CakePHP 2.0 中使用 JsHelper 进行实验,我得到了一个 Request 方法,可以使用 AJAX 调用的结果更新表单字段的值 - 到目前为止,效果很好。但是,在检查表单字段时,它显示:
<input type="hidden" id="JobsPartUnitcost" name="data[JobsPart][unitcost]">5.55</input>
但是当我复制它并首先将其粘贴到上面时,它说
<input type="hidden" id="JobsPartUnitcost" name="data[JobsPart][unitcost]"></input>
当我提交表单时,该值为空。为什么浏览器显示了该值,但底层 DOM 没有注册它?
使用 Mac/Safari、CakePHP 2.0、JQuery
编辑 按照这里的要求是表单数据转储
Array ( [JobsPart] => Array ( [job_id] => 1 [company_id] => 4 [part_id] => 2 [qty] => 3 [unitcost] => ) )
这是 AJAX 代码
$this->Js->get('#JobsPartPartId')->event('change',
$this->Js->request(
array(
'controller'=>'JobsParts',
'action'=>'getPart'
),
array(
'update'=>'#JobsPartUnitcost',
'async' => true,
'method' => 'post',
'dataExpression'=>true,
'data'=> $this->Js->serializeForm(array(
'isForm' => false,
'inline' => true
))
)
)
);
最佳答案
您需要设置 value 属性:
<input type="hidden" value="YOUR VALUE HERE" name="data[Etc][field]" />
您没有将值包装在输入标记中。
关于javascript - 使用js更新表单字段但未在提交的数据中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9228616/