1

そのため、私はサイトで作業しており、フォームに導入されたデータを保存する必要があります。フォームの「アーカイブ」のように、後でクエリするためにそのデータを保存するという考え方です。PHPもサーバーサイドもありません。すべてローカルで作成する必要があります。それを管理する方法はありますか?

ありがとう

4

1 に答える 1

0

あなたはこのようなことを試すことができます:

JS

//first check to see how many form records exist, if none set to 0 in storage
if (!localStorage.getItem('forms')) {
    localStorage.setItem('forms', 0);
}
else {
    forms = localStorage.getItem('forms');
}

//increment to the next form entry
forms++;

//save the form data to localStorage
localStorage.setItem('form.' + forms + '.firstName', document.getElementById('firstName'));

//lastly, save the number of forms to localStorage
localStorage.setItem('forms', forms);


HTML

<input type="text" id="firstName" />



これにより、form.1.firstNamelocalStorageというラベルの付いたレコードが生成されます。出力は、フォームレコードの数の別の単純なチェックであり、反復をループします。

于 2012-11-15T21:06:23.040 に答える