تصف هذه المقالة تنفيذ محدد ألوان بسيط موجه للكائنات بواسطة JS. شاركه للرجوع إليه ، على النحو التالي:
<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html ؛ charset = gb2312"/> <title> document </title> = الدالة (idstr) {this.colorpool = ["#000000" ، "#993300" ، "#333300" ، "#003300" ، "#003366" ، "#000080" ، "#333399" ، "#333333" ، "#800000" ، "#ff 6600 "،"#808000 "،"#008080 "،"#0000FF "،"#666699 "،"#808080 "،"#FF0000 "،"#FF9900 "،"#99CC00 ، "#339966" ، "#33cccc" ، "#3366ff" ، "#800080" ، "#9999999" ، "#ff00ff" ، "#ffcc00" ، "#fff00" ، CCCC "،"#ff99cc "،"#ffcc99 "،"#fff99 "،"#ccfcccc "،"#ccff99 "،"#ccffcc "،"#ccfff "،"#ccffff "،"#99cf "، this.initialize (idstr) ؛} colorpicker.prototype = {initialize: function (idstr) {var count = 0 ؛ var html = '' ؛ var self = this ؛ html+= '<table cellpacing = "5" cellpadding = "0" porderColor = "#000000" style = "cursor: pointer ؛ background:#ece9d8" mce_style = "cursor: pointer ؛ background:#ece9d8"> ؛ // html+= '<tr> <td align = "center" colspan = "8" id = "currentColor" bgColor = "#fffffff"> اللون الحالي </td> </tr>' ؛ لـ (i = 0 ؛ i <5 ؛ i ++) {html+= "<tr>" ؛ لـ (j = 0 ؛ j <8 ؛ j ++) {html+= '<td align = "center" style = "background:'+this.colorpool [count]+'" mce_style = "background:'+this.colorpool [count]+'" unselectable = "on"> </td>' ؛ count ++ ؛ } html+= "</tr>" ؛ } html+= '</table>' ؛ this.trigger = document.getElementById (IDSTR) ؛ this.div = document.createElement ('div') ؛ this.div.innerhtml = html ؛ var tds = this.div.getElementSbyTagName ('td') ؛ لـ (var i = 0 ، l = tds.length ؛ i <l ؛ i ++) {tds [i] .onclick = function () {self.setColor (this.style.backgroundColor) ؛ }} this.div.id = 'mycolorpicker' ؛ this.trigger.parentnode.appendchild (this.div) ؛ this.div.Style.position = 'aboRALUTE' ؛ this.div.style.left = this.trigger.offsetleft + 'px' this.div.style.top = (this.trigger.clientheight + this.trigger.offsettop) + 'px' ؛ //this.hide () ؛ this.trigger.onclick = function () {if (self.div.style.display == 'none') {self.show () ؛ العودة كاذبة } آخر {self.hide () ؛ العودة كاذبة }}} ، setColor: function (c) {this.hide () ؛ document.getElementById ('demo'). style.backgroundColor = c //proeditor.setColor(C) ؛ // حدد الوظيفة بنفسك لتحديد وظيفة setColor} ، Hide: function () {this.div.style.display = 'none'} ، show: function () {this.div.style.display = 'block'} // -> </script> <viv> <a href = " onClick = "initColorPicker () ؛ إرجاع خطأ" معرف "id =" demo "style =" الموضع: مطلق ؛ اليسار: 200px "يمكن للأصدقاء المهتمين بأدوات ألوان JS الرجوع إلى الأدوات عبر الإنترنت لهذا الموقع :
مولد ترميز اللون RGB
RGB COLAL CONSER COMPARISN
أداة مطابقة ألوان الويب عبر الإنترنت
لمزيد من المعلومات حول JavaScript ، يرجى التحقق من موضوعات هذا الموقع: "ملخص لتأثيرات وتقنيات تبديل JavaScript" ، ملخص لمهارات خوارزمية البحث عن JavaScript "،" ملخص لتأثيرات الرسوم المتحركة JavaScript وتقنياتها "، ملخص JavaScript" ، ملخص JavaScript ، "ملخص JavaScripr" ، ملخص JavaScripr "، خوارزميات وتقنيات اجتياز "، و" ملخص استخدام العمليات الرياضية JavaScript "
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.