本文实例讲述了JS实现点击颜色块切换指定区域背景颜色的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下: JS实现点击颜色块切换指定区域的背景颜色 适时切换网页指定区域背景颜色 请选择背景: <br /> function get_cookie(name_to_get) { <p> var cookie_pair<br /> var cookie_name<br /> var cookie_value<br /> var cookie_array = document.cookie.split("; ")<br /> for (counter = 0; counter < cookie_array.length; counter++) {<br /> cookie_pair = cookie_array[counter].split("=")<br /> cookie_name = cookie_pair[0]<br /> cookie_value = cookie_pair[1]<br /> if (cookie_name == name_to_get) {<br /> return unescape(cookie_value)<br /> }<br /> }<br /> return null<br /> }<br /> var bg_color = get_cookie("bgColor_cookie")<br /> function set_color(color_val) {<br /> set_cookie("bgColor_cookie", color_val, 365, "/")<br /> } <p>function set_cookie(cookie_name, cookie_value, cookie_expire, cookie_path, cookie_domain, cookie_secure) {<br /> var cookie_string = cookie_name + "=" + cookie_value<br /> if (cookie_expire) {<br /> var expire_date = new Date()<br /> var ms_from_now = cookie_expire * 24 * 60 * 60 * 1000<br /> expire_date.setTime(expire_date.getTime() + ms_from_now)<br /> var expire_string = expire_date.toGMTString()<br /> cookie_string += "; expires=" + expire_string<br /> } <p> if (cookie_path) {<br /> cookie_string += "; path=" + cookie_path<br /> }<br /> if (cookie_domain) {<br /> cookie_string += "; domain=" + cookie_domain<br /> }<br /> if (cookie_secure) {<br /> cookie_string += "; true"<br /> }<br /> document.cookie = cookie_string<br /> }<br /> if (bg_color) {<br /> bb1.style.backgroundColor = bg_color<br /> }<br /> 希望本文所述对大家的javascript程序设计有所帮助。