У меня есть таблица на веб-странице. Я хочу сохранить информацию в поля ввода с помощью cookie. т.е. я хочу снова открыть мою веб-страницу и увидеть данные с последней веб-страницы.
HTML
<table class="table table-striped" id="table-visual-features">
<thead>
<tr>
<th>Visual Feature</th>
<th>Step</th>
<th>Output</th>
<th>Data Feature</th>
</tr>
</thead>
<tbody>
<tr><td>x</td>
<td><select><option>first</option></select></td>
<td><select><option>output</option></select></td>
<td><input name="data-feature_x" id="value0" class = "feature-execution"/></td>
</tr>
<tr><td>x</td>
<td><select><option>second</option></select></td>
<td><select><option>output</option></select></td>
<td><input name="data-feature_x" id="value1" class = "feature-execution"/></td>
</tr>
<tr><td>x</td>
<td><select><option>third</option></select></td>
<td><select><option>output</option></select></td>
<td><input name="data-feature_x" id="value2" class = "feature-execution"/></td>
</tr>
</tbody>
</table>
Вы можете использовать jQuery Cookie для установки и получения содержимого файлов cookie.
Использование $.cookie.json = true
позволяет хранить данные JSON.
Код:
var getValue = function(id){
return document.querySelector('#'+id).value;
};
var saveCookie = function(){
document.cookie = '';
document.cookie += 'a='+getValue('value0');
document.cookie += 'b='+getValue('value1');
document.cookie += 'c='+getValue('value2');
};
Демо - версия:
http://jsbin.com/IZULuRE/4/edit
Конечно, отредактируйте код для вашего использования :), его единственная демонстрация.