单击后删除 div
Remove a div after is clicked
我想在单击 div 后删除它的父项,并存储值为 true 的 cookie "clicked"。我使用 JavaScript Cookie 来存储 cookie。所以我有一个带有 adsense 的博客,我想隐藏我的广告以防止用户点击 1 次后无效 activity。
这是我的代码:
$("#firstCode").click(function () {
$(this).parent().hide();
var date = new Date();
var h = "1";
date.setTime(date.getTime() + (h * 60 * 60 * 1000));
Cookies.set('clicked', 'true', {expires: date, path: '/'});
});
和html代码:
<div id="codeWrapper">
<div id="firstCode">
<script type="text/javascript">
google_ad_client = "ca-pub-7094677798399606";
google_ad_slot = "8373705259";
google_ad_width = 728;
google_ad_height = 90;
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
但它不起作用。如果有人能找到我的问题所在,我将不胜感激。
您可以使用 jquery remove 从 DOM
中删除一个元素
$("#firstCode").click(function () {
var date = new Date();
var h = "<?php echo html_entity_decode(get_option('fs_time_cookie')); ?>";
date.setTime(date.getTime() + (h * 60 * 60 * 1000));
Cookies.set('clicked', 'true', {expires: date, path: '/'});
$(this).parent().remove();
});
我想在单击 div 后删除它的父项,并存储值为 true 的 cookie "clicked"。我使用 JavaScript Cookie 来存储 cookie。所以我有一个带有 adsense 的博客,我想隐藏我的广告以防止用户点击 1 次后无效 activity。
这是我的代码:
$("#firstCode").click(function () {
$(this).parent().hide();
var date = new Date();
var h = "1";
date.setTime(date.getTime() + (h * 60 * 60 * 1000));
Cookies.set('clicked', 'true', {expires: date, path: '/'});
});
和html代码:
<div id="codeWrapper">
<div id="firstCode">
<script type="text/javascript">
google_ad_client = "ca-pub-7094677798399606";
google_ad_slot = "8373705259";
google_ad_width = 728;
google_ad_height = 90;
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
但它不起作用。如果有人能找到我的问题所在,我将不胜感激。
您可以使用 jquery remove 从 DOM
中删除一个元素$("#firstCode").click(function () {
var date = new Date();
var h = "<?php echo html_entity_decode(get_option('fs_time_cookie')); ?>";
date.setTime(date.getTime() + (h * 60 * 60 * 1000));
Cookies.set('clicked', 'true', {expires: date, path: '/'});
$(this).parent().remove();
});