JS Implementation Click Color block to switch the color of the specified area background _javascript tips

Source: Internet
Author: User

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:

Copy Code code 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>
&LT;TD colspan= "2" >
<div align= "center" >
<table border= "0" width= "90%" cellpadding= "0" style= "border-collapse:collapse" "height=" id= "Table2" >
&LT;TR&GT;&LT;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 ">
&LT;TR&GT;&LT;TD width= "219" ><p align= "right" ><font color= "#808080" ><span style= "font-size:9pt" > Please select Background:</span></font></td>
&LT;TD width= "281" ><div align= "center" ><table border= "1" width= "" cellspacing= "0" cellpadding= "0" height= "id=" "table1" style= "Border-collapse:collapse" bordercolor= "#FFFFFF" >
<tr>
&LT;TD width= "onclick=" bb1.style.backgroundcolor= ' FDFDF0 ' set_color (' FDFDF0 ') "bgcolor=" #FDFDF0 "></td >
&LT;TD onclick= "bb1.style.backgroundcolor= ' b1d5f3" set_color (' b1d5f3 ') "bgcolor=" #B1D5F3 "width=" >
&LT;TD onclick= "bb1.style.backgroundcolor= ' b4e7d9" set_color (' b4e7d9 ') "bgcolor=" #B4E7D9 "width=" >
&LT;TD onclick= "bb1.style.backgroundcolor= ' f1e8ff" set_color (' f1e8ff ') "bgcolor=" #F1E8FF "width=" >
&LT;TD onclick= "bb1.style.backgroundcolor= ' e8fff3" set_color (' e8fff3 ') "bgcolor=" #E8FFF3 "width=" >
&LT;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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.