笔试题--js为各div加不同背景颜色

    技术2024-10-02  50

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('div').each(function () { var hue = 'rgb(' + (Math.floor((256-199)*Math.random()) + 200) + ',' + (Math.floor((256-199)*Math.random()) + 200) + ',' + (Math.floor((256-199)*Math.random()) + 200) + ')'; $(this).css("background-color", hue); }); }); </script> </head> <body> <div class='A kk'>2....</div> <div class='A B'>1....</div> <div class='A C'>7....</div> <div class='A B C'>4....</div> <div class='B C'>8....</div> <div class='A C'>9....</div> <div class='A B'>0....</div> <div class='C B'>0....</div> <div class='B'>2....</div> <div class='C'>3....</div> <div class='A'>5....</div> </body> </html>

    效果图:

    Processed: 0.009, SQL: 9