2012-02-07 64 views
0

第1頁有10個字段,第2頁有超鏈接。第2頁到第1頁也有超鏈接。我填寫5個字段並單擊超鏈接。然後我點擊頁面2上的超鏈接並返回到page1。是否可以保存填充的字段以及如何? 附加問題:如果page2修改page1的字段會怎麼樣。例如,在多選區域中創建新的選擇。如何保存(暫時)表單數據?

回答

1

您可以點擊鏈接後,纔去到另一個頁面保存通過javascript使用cookie填充字段。例如,可以使用這個jQuery插件jQuery-cookie。如文件所述:

A simple, lightweight jQuery plugin for reading, writing and deleting cookies. 

Create session cookie: 
$.cookie('the_cookie', 'the_value'); 

Create expiring cookie, 7 days from then:  
$.cookie('the_cookie', 'the_value', { expires: 7 }); 

Create expiring cookie, valid across entire page:  
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' }); 

Read cookie:  
$.cookie('the_cookie'); // => 'the_value' 
$.cookie('not_existing'); // => null 

Delete cookie by passing null as value:  
$.cookie('the_cookie', null); 

Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie. 
2

Django已經實現了允許在多個網頁上拆分表單的解決方案。它被稱爲表單嚮導。請查看here瞭解本教程。

編輯1#

檢查這個問題了:Django Passing data between viewsHow do you pass or share variables between django views?

+0

我不需要拆分表格。問題在於在點擊鏈接時進行操作。只有使用JavaScript或者Django纔有特殊功能? – DSblizzard 2012-02-07 22:28:26

+0

已經有一些關於你的問題在stackoverflow上的答案。 – szaman 2012-02-08 07:01:58

+0

主要的問題不是保存數據,而是點擊鏈接。沒有JavaScript,這是不可能的,因爲我能理解。不管怎麼說,還是要謝謝你。 – DSblizzard 2012-02-08 22:29:47