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