2
全部创建一个cakephp(使用2.1.2)页面。我们提示用户输入他们之后有多少个字段(一个int),然后我们希望页面对输入的数字使用for循环。cakephp javascript动态更新
这里是附加页面
<h2>Please select how many fields you wish to add</h2></br>
<?php
print $this->Session->flash('flash', array('element' => 'alert'));
echo $this->Form->create('Field', array('action'=>'add'));
For(int i=0; i<'flash'; i++)
{
echo $this->Form->input('name',array('label'=>'Please Enter Field Name: ', 'type'=>'text'));
echo $this->Form->input('description',array('label'=>'Please Enter Field Description: ', 'type'=>'text'));
}
echo $this->Form->end('Click Here To Submit Template');
?>
这里的代码是为警报
<script type="text/javascript">
prompt('How many fields?','<?php print $message; ?>');
</script>
的问题是我们如何创造与alert.ctp一个变量,然后就能代码将该变量用于for循环来打印出一个需要用户输入的表单。
编辑:
JavaScript函数:
<script type="text/javascript">
var number_of_fields=prompt("How many fields?",'<?php print $message; ?>');
var field_html="";
for (i=0; i<number_of_fields; i++)
{
field_html +='<input type="text" name="data[FIELD]['+i+'][name]">';
}
$("#FORMID").append(field_html);
</script>
查看:
<?php
print $this->Session->flash('flash', array('element' => 'alert'));
echo $this->Form->create('Field', array('action'=>'add'));
echo $this->Form->end('Click Here To Submit Template');
?>
现在没有错误,但不能显示任何领域。我们在打印字段的视图中放置了什么(这将更多地输入 - 所以用户可以创建一个字段)?
刚才编辑的代码@Sreeni。如果Javasctipt函数具有for循环,我们在视图中放入了什么? – user1402677 2012-07-30 14:04:26