本文實例講述了JS實作點擊顏色區塊切換指定區域背景顏色的方法。分享給大家供大家參考。具體實作方法如下:
|
请选择背景: |
var cookie_pair
var cookie_name
var cookie_value
var cookie_array = document.cookie.split("; ")
for (counter = 0; counter
cookie_pair = cookie_array[counter].split("=")
cookie_name = cookie_pair[0]
cookie_value = cookie_pair[1]
if (cookie_name == name_to_get) {
返回 unescape(cookie_value)
}
}
返回空
}
var bg_color = get_cookie("bgColor_cookie")
函數 set_color(color_val) {
set_cookie("bgColor_cookie", color_val, 365, "/")
}
函數 set_cookie(cookie_name, cookie_value, cookie_expire, cookie_path, cookie_domain, cookie_secure) {
var cookie_string = cookie_name "= cookie_value
if (cookie_expire) {
var expire_date = new Date()
var ms_from_now = cookie_expire * 24 * 60 * 60 * 1000
expire_date.setTime(expire_date.getTime() ms_from_now)
var expire_string = expire_date.toGMTString()
cookie_string =“;expires=”expire_string
}
if (cookie_path) {
Cookie_string = "; path=" cookie_path
}
if (cookie_domain) {
cookie_string = ";domain="cookie_domain
}
if (cookie_secure) {
cookie_string = "; true"
}
document.cookie = cookie_string
}
if (bg_color) {
bb1.style.backgroundColor = bg_color
}
>腳本
身體>