有一個在confections2.js
document.getElementById('Order').on('click', function(){
的函數,而不是正確的語法。相反,它應該是
document.getElementById('Order').onclick = function() {
var name = document.getElementById('consumer_name').value;
Cookies.set('consumer_name', name).get('consumer_name');
var chocolate = document.getElementById('chocolate').value;
Cookies.set('chocolate', chocolate).get('chocolate');
var sugar = document.getElementById('sugar').value;
Cookies.set('sugar', sugar).get('sugar');
var lemon = document.getElementById('lemon').value;
Cookies.set('lemon', lemon).get('lemon');
}
然後index.html中
<input type="button" value="Reset" onclick="clearCookies();">
改變然後改變的JavaScript功能 - 包括重載以及函數名。看來,清除()不會產生任何結果:(
function clearCookies(){
Cookies.set('consumer_name', null);
Cookies.set('chocolate', 0);
Cookies.set('lemon',0);
Cookies.set('sugar',0);
location.reload();
};
它重置值爲null和0,但它實際上並沒有刪除Cookie,可以修改這樣的 -
。
function clearCookies(){
// Cookies.set('consumer_name', null);
// Cookies.set('chocolate', 0);
// Cookies.set('lemon',0);
// Cookies.set('sugar',0);
delete_cookie('consumer_name');
delete_cookie('chocolate');
delete_cookie('lemon');
delete_cookie('sugar');
location.reload();
};
function delete_cookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}