单击以下链接后,我有此 jquery 代码用于隐藏广告框:
$('a.close').click(function () {
var parent = $(this).parent().parent();
var adid = $(parent).attr('id');
$.ajax({
type: "POST",
url: "./setcookie.php",
data: "adid=" + adid,
cache: false,
dataType: 'json',
success: function (cook) {
if (cook.set === 'success') {
parent.fadeOut(1000);
}
},
error: function () {
$(".guestwarn").html("<font color='red'>There was an error submitting the form. Please try again.</font>").fadeIn(1000);
}
});
return false;
});
所以我想通过cookies关闭框。我的 html(php) 是:
<?php if(isset($_COOKIE[ "msg1"])){?>
<div id="msg1" class="msgbox">
<div class="guestwarn">
<a href="#" class="close">X</a>
Something goes here...
</div>
</div>
<?php } ?>
所以我的工作 setcookie.php 是:
$adcookies = array();
$value = $_POST['adid'];
if ($value) {
setcookie($value, $value, time() + 3600);
if (isset($_COOKIE[$value])) {
$adcookies['set'] = "success";
} else {
$adcookies['set'] = "error";
}
echo json_encode($adcookies);
}
为什么 adbox (.msgbox) 在两次点击后隐藏?代码有什么问题?谢谢你