- 论坛徽章:
- 0
|
在动态网站中,经常会有允许用户在客户端自定义颜色显示某些信息的情况,如留言板的颜色,这可以通过在网页中加入一个拾色器来实现,当用户单击颜色块时,弹出拾色器供选择,当用户选择完毕后,关闭拾色器,并把选中的颜色赋予颜色块,在当用户用拾色器时 还要显示该颜色的颜色值
首先,创建需要调用网页拾色器的页面,我在这里定义为 index.jsp
script language="javascript">
function colorpick(field){
var rtn = window.showModalDialog("color.jsp","","dialogWidth:225px;dialogHeight:170px;status:no;help:no;scrolling=no;scrollbars=no");
if(rtn!=null)
field.style.background=rtn;
return;
}
/script>
body>
选择颜色 :
input name="color" type="text" id="color" size="3" readonly="yes" style="background-color:#000000" onClick="colorpick(this);">
/body>
其次,建立拾色器页面 color.jsp
%@ page contentType="text/html; charset=gb2312" language="java"%>
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=gb2312">
title>网页拾色器/title>
/head>
body>
script language="JavaScript">
');
document.write('');
document.write('');
document.write('');
document.write('');
}
function Mtr(R, B) {
document.write('');
for (var i = 0; i ')
}
function Mtable(B) {
document.write('');
for (var i = 0; i ');
}
function Mcube() {
document.write(''); //
for (var i = 0; i ');
}
document.write('');
Mtable(h)
document.write('');
}
if(i%3==0){
document.write('');
}
document.write('');
}
Mcube()
-->
/script>
/body>
/html>
完毕,大家可以当作工具使用,以后当做某些项目的时候,比如具有UBB功能的在线论坛,网站聊天室或者网页换肤功能的时候 就可以运用本实例! 呵呵
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/72940/showart_1129524.html |
|