我使用HTML5本地存储来存储值,"点击"并且只显示一个弹出窗口,如果该值设置为" false",在弹出窗口中单击确定将值更改为" true"然后弹出窗口不再被触发。 我一直在测试这个,代码看起来很好,没有错误,但它仍然显示每次点击的弹出窗口。
jQuery( document ).ready(function() {
localStorage.setItem('clicked',"false");
var clicked = localStorage.getItem('clicked');
if(clicked = "false") {
jQuery('.external').click( function(e) {
var r = confirm("You are now leaving");
if (r == true) {
localStorage.setItem('clicked',"true");
window.open(jQuery(this).prop('href'),"_blank");
} else {
}
e.preventDefault();
});
}
else {
}
}
答案 0 :(得分:0)
jQuery( document ).ready(function() {
localStorage.setItem('clicked',"false");
var clicked = localStorage.getItem('clicked');
jQuery('.external').click( function(e) {
e.preventDefault();
var clicked = localStorage.getItem('clicked')
if (clicked === "true") {
return;
}
var r = confirm("You are now leaving");
if (r == true) {
localStorage.setItem('clicked',"true");
window.open(jQuery(this).prop('href'),"_blank");
} else {
}
});
});