The example of this article tells JS implementation of the Click Color block to switch the specified area background color. Share to everyone for your reference. The implementation methods are as follows:
<title>js Implement click Color block to toggle the background color of the specified area </title>
<body>
<div align= "center" >
<table bgcolor= #F8F8F8 border= "0" width= "0" cellpadding= "style=" Border-collapse:collapse "height=" 180 "id=" BB1 ">
<tr>
<TD colspan= "2" >
<div align= "center" >
<table border= "0" width= "90%" cellpadding= "0" style= "border-collapse:collapse" "height=" id= "Table2" >
<TR><TD style= "line-height:150%" ><span style= "font-size:14px" > Timely switch page Specify area background color </span></ Td>
</tr></table>
</div>
</td>
</tr></table></div>
<div align= "center" >
<table border= "0" width= "cellpadding=" 0 "style=" border-collapse:collapse "height=" "id=" table1 ">
<TR><TD width= "219" ><p align= "right" ><font color= "#808080" ><span style= "font-size:9pt" > Please select Background:</span></font></td>
<TD width= "281" ><div align= "center" ><table border= "1" width= "" cellspacing= "0" cellpadding= "0" height= "id=" "table1" style= "Border-collapse:collapse" bordercolor= "#FFFFFF" >
<tr>
<TD width= "onclick=" bb1.style.backgroundcolor= ' FDFDF0 ' set_color (' FDFDF0 ') "bgcolor=" #FDFDF0 "></td >
<TD onclick= "bb1.style.backgroundcolor= ' b1d5f3" set_color (' b1d5f3 ') "bgcolor=" #B1D5F3 "width=" >
<TD onclick= "bb1.style.backgroundcolor= ' b4e7d9" set_color (' b4e7d9 ') "bgcolor=" #B4E7D9 "width=" >
<TD onclick= "bb1.style.backgroundcolor= ' f1e8ff" set_color (' f1e8ff ') "bgcolor=" #F1E8FF "width=" >
<TD onclick= "bb1.style.backgroundcolor= ' e8fff3" set_color (' e8fff3 ') "bgcolor=" #E8FFF3 "width=" >
<TD onclick= "bb1.style.backgroundcolor= ' Cdcdde" set_color (' Cdcdde ') "bgcolor=" #CDCDDE "width=" >
</tr>
</table>
</div></td></tr></table>
</div>
<script language=javascript>
function Get_cookie (name_to_get) {
var cookie_pair
var cookie_name
var cookie_value
var cookie_array = Document.cookie.split (";")
for (counter = 0; counter < cookie_array.length; counter++) {
&nbs p; Cookie_pair = cookie_array[counter].split ("=")
Cookies _name = cookie_pair[0]
cookie_value = cookie_pair[1]
& nbsp; if (cookie_name = = name_to_get) {
return unescape (cookie_value)
}
{
return null
}
var bg_color = Get_cookie ("Bgcolor_cookie")
function Set_color ( Color_val) {
set_cookie ("Bgcolor_cookie", Color_val, 365, "/")
}
Function Set_cookie (cookie_name, Cookie_value, Cookie_expire, Cookie_path, Cookie_domain, cookie_secure) {
var cookie_string = cookie_name + "=" + Cookie_value
if (cookie_expire) {
&N bsp; var expire_date = new Date ()
var Ms_from_now = cookie_expire * * * * 1000
expire_date.settime (E Xpire_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
}
</script>
</body>
I hope this article will help you with your JavaScript programming.