0
我需要一些幫助,我從我的朋友那裏得到了cookie接受的jquery代碼,我們必須在丹麥使用它。在身體中調用cookie-jquery函數?
我的問題是,我真的不知道如何在HTML中的身體調用函數?
有人可以幫忙,我得到了jsFiddle中的代碼,應該很容易讓你看一看。
HTML:
This is a test
<script>
jQuery(document).load(_cookieAccept);
</script>
JS:
var _cookieAccept = {
init: function() {
if (this.hasAccepted()) {
return;
}
//
var bar = $j('<div>')
.addClass('cookieAccept')
.append($j('<span>').html('<img src="http://www.computerworld.dk/common/images/cookie_warning_1.gif" />Websitet anvender cookies til at huske dine indstillinger, statistik og at målrette annoncer. <a class="readMore" href="/privacy" target="_blank">Læs mere</a>'))
.append($j('<a>').attr('href', 'javascript:void(0)').addClass('accept').html('OK').click(this.clickAccept))
//
bar.css({
position: 'fixed',
left: 0,
bottom: 0,
width: '100%',
backgroundColor: 'rgba(0, 0, 0, 0.7)',
color: '#ffffff',
padding: '15px',
fontSize: 16,
lineHeight: '20px',
fontFamily: 'Arial',
zIndex: 10000,
textAlign: 'left'
});
bar.find('a.readMore').css({
color: '#ffffff',
textDecoration: 'underline',
fontWeight: 'normal'
});
bar.find('a.accept').css({
float: 'right',
marginRight: '50px',
backgroundColor: '#ffffff',
padding: '5px 20px',
borderRadius: '4px',
color: '#000000',
fontSize: '14px'
});
bar.find('a.accept').hover(function() {
$j(this).css('backgroundColor', '#7c94a0');
}, function() {
$j(this).css('backgroundColor', '#ffffff');
});
//
$j('body').append(bar);
},
/**
*
*/
hasAccepted: function() {
return (document.cookie.indexOf('cookieAccept=Yes') !== -1);
},
/**
*
*/
setAccept: function() {
var expire = new Date();
expire.setDate(expire.getDate() + (365 * 10));
document.cookie = 'cookieAccept=Yes;expires=' + expire.toGMTString() + ';path=/';
},
/**
*
*/
clickAccept: function() {
_cookieAccept.setAccept();
$j('div.cookieAccept').hide();
}
};
$j(document).ready($j.proxy(_cookieAccept.init, _cookieAccept));
'.load()'的參數應該是一個調用的函數,而不是一個對象。 – Barmar