我正在尝试将 jQuery 事件存储在数据库中。
//Calling this Function On Click
function trackevent(event){
window.events.push(event)
}
$.each(window.events, function(i, item){
console.log(i +" - "+ $.parseJSON(item));
});
事件被存储到数组中。这很酷,但如果我尝试循环访问,window.events
我将无法取回 jQuery 事件 JSON。我无法弄清楚我的错误。任何建议都会有所帮助。
如果我将 parseJSON 更改为 JSON.stringify,我会收到此错误
$.each(window.events, function(i, item){
console.log(i +" - "+ JSON.stringify(item));
});
$(document).ready(function(){
window.events = []
// Function to enable the hidden checkbox button
$(".answers_checkbox").click(function(){
current_click = $(this).attr("data-attr");
// If the Hidden checkbox is Checked , it means its already selected (blue)
if($("."+this.id).attr('checked') == 'checked') {
$(this).css('background-image', '');
} else {
// Changing the Background Image to current_click option
$(this).css('background-image',"url('/assets/choice_buttons/choice"+current_click+"_Sq_Blue.png')");
}
$("."+this.id).attr('checked',!$("."+this.id).attr('checked'));
trackevent(event);
});
function trackevent(event){
window.events.push(event)
}
});
// Function to Save Events
$(window).bind('beforeunload', function(){
$.each(window.events, function(i, item){
console.log(i +" - "+ item);
});
});