JS實(shí)現(xiàn)簡單面向?qū)ο蟮念伾x擇器實(shí)例
來源:易賢網(wǎng) 閱讀:1280 次 日期:2016-07-06 17:02:23
溫馨提示:易賢網(wǎng)小編為您整理了“JS實(shí)現(xiàn)簡單面向?qū)ο蟮念伾x擇器實(shí)例”,方便廣大網(wǎng)友查閱!

本文實(shí)例講述了JS實(shí)現(xiàn)簡單面向?qū)ο蟮念伾x擇器。分享給大家供大家參考,具體如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>Untitled Document</title>

</head>

<body>

<script type="text/JavaScript">

<!--

var colorPicker = function(idStr){

 this.colorPool = ["#000000","#993300","#333300","#003300","#003366","#000080","#333399","#333333","#800000","#FF6600","#808000","#008000","#008080","#0000FF","#666699","#808080","#FF0000","#FF9900","#99CC00","#339966","#33CCCC","#3366FF","#800080","#999999","#FF00FF","#FFCC00","#FFFF00","#00FF00","#00FFFF","#00CCFF","#993366","#CCCCCC","#FF99CC","#FFCC99","#FFFF99","#CCFFCC","#CCFFFF","#99CCFF","#CC99FF","#FFFFFF"];

 this.initialize(idStr);

}

colorPicker.prototype = {

 initialize: function(idStr){

  var count=0;

  var html = '';

  var self = this;

  html+= '<table cellspacing="5" cellpadding="0" border="2" bordercolor="#000000" style="cursor:pointer;background:#ECE9D8" mce_style="cursor:pointer;background:#ECE9D8" >';

  // html+= '<tr><td align="center" colspan="8" width="160" height="20" id="currentColor" bgcolor="#ffffff">當(dāng)前顏色</td></tr>';

  for(i=0;i<5;i++)

  {

   html+= "<tr>";

   for(j=0;j<8;j++)

   {

    html+= '<td align="center" width="20" height="20" 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');

  for(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 = 'absolute';

  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();

    return false;

   }else{

    self.hide();

    return false;

   }

  }

 },

 setColor : function(c){

  this.hide();

  document.getElementById('demo').style.backgroundColor = c //proEditor.setColor(c); //自己定義函數(shù)決定setColor的功能

 },

 hide : function(){

  this.div.style.display = 'none'

 },

 show : function(){

  this.div.style.display = 'block'

 }

}

// -->

</script>

<div >

<a href="#" mce_href="#" onclick="initColorPicker();return false" id="demo" style="position:absolute;left:200px">顏色選擇</a>

</div>

<script type="text/javascript">

<!--

function initColorPicker(){

 picker = new colorPicker('demo');

}

// -->

</script>

</body>

</html>

希望本文所述對大家JavaScript程序設(shè)計(jì)有所幫助。

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:JS實(shí)現(xiàn)簡單面向?qū)ο蟮念伾x擇器實(shí)例
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機(jī)號
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報警專用圖標(biāo)