代码如下:
<span
style="font-size:14px"><!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/htmlcharset=utf-8">
<title>富文本编辑器</title>
</head>
<body>
<fieldset>
<legend>编辑区</legend>
<div>
<form>
字体颜色:
<select
onchange="setFontColor(this)">
<option
value="black">Black
</option>
<option
value="red">Red
</option>
<option
value="green">Green
</option>
<option
value="blue">Blue
</option>
</select>
字体样式:
<select
onchange="setFontStyle(this)">
<option
value="bold">Bold
</option>
<option
value="italic">Italic
</option>
<option
value="underline">Underline
</option>
<option
value="striketthrough">StriketThrough
</option>
</select>
字体名称:
<select
onchange="setFontFamily(this)">
<option
value="serif">Serif
</option>
<option
value="sans-serif">Sans-serif
</option>
<option
value="monospace">Monospace
</option>
<option
value="comic
sans
ms">Comic
Sans
</option>
</select>
</form>
</div>
<br/>
<div
id="editableText"
contenteditable="true"
style="width:400pxmin-height:100pxborder:2px
dashed
#ccc"></div>
</fieldset>
<script
type="text/javascript">
function
setFontColor(obj)
{
document.execCommand("forecolor",false,obj.value)
}
function
setFontStyle(obj)
{
document.execCommand(obj.value,false,null)
}
function
setFontFamily(obj)
{
document.execCommand("fontname",false,obj.value)
}
</script>
</body>
</html></span>
在线演示:http://jsfiddle.net/Web_Code/nPNv3/embedded/result/
不足之处还请谅解,提出指正方法
本文实例讲述了js实现选中复选框文字变色的方法。分享给大家供大家参考。具体如下:这里实现选中复选框时,文字加上一个背景色,变通一下,还是很有用的。
运行效果如下图所示:
在线演示地址如下:
http://demo.jb51.net/js/2015/js-checkbox-cha-font-color-codes/
具体代码如下:
<html>
<head>
<title>选中复选框文字变色</title>
<style>
.checkbox
{
background-Color:e-xpression(this.checked?'yellow':'buttonface')
}
</style>
</head>
<script>
function
chaCloor(field){
var
pig
=
field.checked
pig?field.nextSibling.style.backgroundColor="skyblue":field.nextSibling.style.backgroundColor="white"
}
</script>
<body>
<table
height=48
width=136>
<tr>
<td><input
type="checkbox"
onClick="chaCloor(this)"><span>网页特效</span></td>
</tr>
<tr>
<td><input
type="checkbox"
onClick="chaCloor(this)"><span>源码下载</span></td>
</tr>
<tr>
<td><input
type="checkbox"
onClick="chaCloor(this)"><span>编程软件</span></td>
</tr>
</table>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
下拉菜单关键在于HTML的布局和CSS的样式写法。这有这两个写好了后,js操作起来才非常的简单。下面是简单例子,仅供参考:<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head><meta http-equiv="Content-Type" content="text/html charset=gb2312" />
<title>js菜单演示_怎么使用js_js下拉菜单_简单js下拉菜单_怎么做js下拉菜单</title>
<style type="text/css">
*{margin:0padding:0border:0}
body {font-family: arial, 宋体, seriffont-size:12px}
#nav {line-height: 24px list-style-type: none background:#666}
#nav a {display: block width: 80px text-align:center}
#nav a:link {color:#666 text-decoration:none}
#nav a:visited {color:#666text-decoration:none}
#nav a:hover {color:#FFFtext-decoration:nonefont-weight:bold}
#nav li {float: left width: 80px background:#CCC}
#nav li a:hover{background:#999}
#nav li ul {line-height: 27px list-style-type: nonetext-align:leftleft: -999em width: 180px position: absolute}
#nav li ul li{float: left width: 120pxbackground: #F6F6F6}
#nav li ul a{display: block width: 100pxtext-align:leftpadding-left:20px}
#nav li ul a:link {color:#666 text-decoration:none}
#nav li ul a:visited {color:#666text-decoration:none}
#nav li ul a:hover {color:#F3F3F3text-decoration:nonefont-weight:normalbackground:#C00}
#nav li:hover ul {left: auto}
#nav li.onhover ul {left: auto}
#content {clear: left}
</style>
<script type="text/javascript">
function menu() {
var oLi = document.getElementById("nav").getElementsByTagName("li")
for (var i=0 i<oLi.length i++) {
oLi[i].onmouseover=function() {
this.className+=(this.className.length>0? " ": "") + "onhover"
}
oLi[i].onMouseDown=function() {
this.className+=(this.className.length>0? " ": "") + "onhover"
}
oLi[i].onMouseUp=function() {
this.className+=(this.className.length>0? " ": "") + "onhover"
}
oLi[i].onmouseout=function() {
this.className=this.className.replace(new RegExp("( ?|^)onhover\b"),"" )}}}
window.onload=menu
</script></head>
<body>
<ul id="nav">
<li><a href="http://jingyan.baidu.com/article/fc07f98917a56f12ffe5198a.html" target="_blank" >动漫之家</a>
<ul>
<li>
<a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >下拉一</a></li>
<li><a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >下拉二</a></li>
<li><a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >下拉三</a></li>
<li><a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >下拉四</a></li>
</ul></li><li><a href="http://jingyan.baidu.com/article/e73e26c0cfa01724adb6a795.html" target="_blank" >js详解</a><ul>
<li><a href="http://jingyan.baidu.com/article/e73e26c0cfa01724adb6a795.html" target="_blank" >下拉一</a></li>
<li><a href="http://jingyan.baidu.com/article/e73e26c0cfa01724adb6a795.html" target="_blank" >下拉二</a></li>
<li><a href="http://jingyan.baidu.com/article/e73e26c0cfa01724adb6a795.html" target="_blank" >下拉三</a></li>
<li><a href="http://jingyan.baidu.com/article/e73e26c0cfa01724adb6a795.html" target="_blank" >下拉四</a></li></ul></li>
<li><a href="http://jingyan.baidu.com/article/08b6a591f09cfc14a8092293.html" target="_blank" >js运用</a>
<ul><li><a href="http://jingyan.baidu.com/article/08b6a591f09cfc14a8092293.html" target="_blank" >下拉一</a></li>
<li><a href="http://jingyan.baidu.com/article/08b6a591f09cfc14a8092293.html" target="_blank" >下拉二</a></li>
<li><a href="http://jingyan.baidu.com/article/08b6a591f09cfc14a8092293.html" target="_blank" >下拉三</a></li>
<li><a href="http://jingyan.baidu.com/article/08b6a591f09cfc14a8092293.html" target="_blank" >下拉四</a></li></ul></li>
<li><a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >关于我们</a>
<ul><li><a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >下拉一</a></li>
<li><a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >下拉二</a></li>
<li><a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >下拉三</a></li>
<li><a href="http://jingyan.baidu.com/article/363872ecedf4486e4ba16f92.html" target="_blank" >下拉四</a></li>
</ul></li><li><a href="http://jingyan.baidu.com/article/cdddd41c5e873153cb00e193.html" target="_blank" >js在线演示</a>
<ul><li><a href="http://jingyan.baidu.com/article/cdddd41c5e873153cb00e193.html" target="_blank" >下拉一</a></li>
<li><a href="http://jingyan.baidu.com/article/cdddd41c5e873153cb00e193.html" target="_blank" >下拉二</a></li>
<li><a href="http://jingyan.baidu.com/article/cdddd41c5e873153cb00e193.html" target="_blank" >下拉三</a></li>
<li><a href="http://jingyan.baidu.com/article/cdddd41c5e873153cb00e193.html" target="_blank" >下拉四</a></li></ul></li>
<li><a href="http://jingyan.baidu.com/article/76a7e409bb3c33fc3b6e1593.html" target="_blank" >联系我们</a>
<ul><li><a href="http://jingyan.baidu.com/article/76a7e409bb3c33fc3b6e1593.html" target="_blank" >下拉一</a></li>
<li><a href="http://jingyan.baidu.com/article/76a7e409bb3c33fc3b6e1593.html" target="_blank" >下拉二</a></li>
<li><a href="http://jingyan.baidu.com/article/76a7e409bb3c33fc3b6e1593.html" target="_blank" >下拉三</a></li>
<li><a href="http://jingyan.baidu.com/article/76a7e409bb3c33fc3b6e1593.html" target="_blank" >下拉四</a></li></li></ul>
</body>
</html>