请教一个复选框的问题!

我想在文本框的旁边加几个复选框,当选中就可以改变文本框中文字的颜色,大小,当不选时就恢复原状,我应该怎么做呢?请各位大虾指教!!!
---------------------------------------------------------------

1<input onclick="alert(txt1.style.fontSize);txt1.style.color=(txt1.style.color=='#000000')?'#ff0000':'#000000';txt1.style.fontSize=(txt1.style.fontSize=='12pt')?'9pt':'12pt';" type="checkbox"/>
1<input id="txt1" style="color:#000000;font-size:12pt;" type="text" value="test"/>

---------------------------------------------------------------

在文本框中编程实现,onFocus里设置它的color ,及大小
---------------------------------------------------------------

1<input onclick="txt1.style.color=(txt1.style.color=='#000000')?'#ff0000':'#000000';txt1.style.fontSize=(txt1.style.fontSize=='12pt')?'9pt':'12pt';" type="checkbox"/>
1<input id="txt1" style="color:#000000;font-size:12pt;" type="text" value="test"/>

---------------------------------------------------------------

1<input id="xx" onselect="sw()" type="checkbox"/>
1<input id="ss"/>
 1<script>   
 2function sw(){   
 3if(xx.selected==true)   
 4document.all.ss.style.color="red";   
 5document.all.ss.style.fontSize="14pt";   
 6}   
 7else{   
 8document.all.ss.style.color="black";   
 9document.all.ss.style.fontSize="9pt";   
10  
11}   
12</script>

---------------------------------------------------------------

1<html>
2<body>
3<input id="pp" type="text" value="exam"/>color:<input onclick="if(this.checked==true) pp.style.color='red'; else pp.style.color='black' " type="checkbox" value="red"/>size:<input onclick="if(this.checked==true) pp.style.fontSize='20'; else pp.style.fontSize='14'" type="checkbox" vlaue="20"/>
4</body>
5</html>

---------------------------------------------------------------

最好写成函数

1<script language="JavaScript">   
2<!--   
3function chg(t,o,s,str){   
4var tt=document.frm.elements[t]   
5tt.style[s]=o.checked?str:''   
6}   
7//-->   
8</script>
1<form name="frm">
2<input name="test" type="text"/>
3<input onclick="chg('test',this,'fontSize','15pt')" type="checkbox"/>
4<input onclick="chg('test',this,'color','red')" type="checkbox"/>
5<input onclick="chg('test',this,'backgroundColor','yellow')" type="checkbox"/>
6</form>

---------------------------------------------------------------

测试成功的代码:

 1<html>
 2<head>
 3<title>Untitled Document</title>
 4<script language="JavaScript">   
 5function ddd(ss)   
 6{   
 7alert(ss)   
 8if (ss=='color')   
 9{   
10document.changestyle.text1.style.color=document.changestyle.color1.value;   
11return;   
12}   
13if (ss=='size')   
14{   
15document.changestyle.text1.style.fontSize=document.changestyle.size1.value;   
16return;   
17}   
18}   
19</script>
20<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
21</head>
22<body>
23<form action="" method="post" name="changestyle">
24<input name="text1" type="text"/>   
25大小   
26<select name="size1" onchange="ddd('size')">
27<option value="10px">10px</option>
28<option value="11px">11px</option>
29<option value="12px">12px</option>
30<option value="13px">13px</option>
31<option value="14px">14px</option>
32</select>   
33颜色   
34<select name="color1" onchange="ddd('color')">
35<option value="red">red</option>
36<option value="blue">blue</option>
37<option value="yellow">yellow</option>
38</select>
39</form>
40</body>
41</html>

---------------------------------------------------------------

http://www.csdn.net/cnshare/soft/5/5819.shtm
---------------------------------------------------------------

 1<html>
 2<head>
 3<title>New Page 1</title>
 4</head>
 5<body>
 6<form action="" method="POST">
 7<p><input name="t1" size="20" type="text"/>
 8<input name="C1" onclick="if(this.checked){t1.style.color='red'} else{t1.style.color='black'}" type="checkbox" value="ON"/>red    
 9<input name="C2" type="checkbox" value="ON"/>green</p>
10</form>
11</body>
12</html>

---------------------------------------------------------------

 1<html>
 2<head>
 3<title>New Page 1</title>
 4</head>
 5<body>
 6<form action="" method="POST">
 7<p><input name="t1" size="20" type="text"/>
 8<input name="C1" onclick="if(this.checked){t1.style.color='red'} else{t1.style.color='black'}" type="checkbox" value="ON"/>red    
 9<input name="C2" onclick="if(this.checked){t1.style.fontSize='18'} else{t1.style.fontSize='15'}" type="checkbox" value="ON"/>18px</p>
10</form>
11</body>
12</html>
Published At
Categories with Web编程
comments powered by Disqus