请教一个复选框的问题!

zl13 2003-07-03 10:08:41
我想在文本框的旁边加几个复选框,当选中就可以改变文本框中文字的颜色,大小,当不选时就恢复原状,我应该怎么做呢?请各位大虾指教!!!
...全文
37 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaoweiwei 2003-07-03
  • 打赏
  • 举报
回复
<html>

<head>

<title>New Page 1</title>
</head>

<body>

<form method="POST" action="">

<p><input type="text" name="t1" size="20">
<input type="checkbox" name="C1" value="ON" onclick="if(this.checked){t1.style.color='red'} else{t1.style.color='black'}">red 
<input type="checkbox" name="C2" value="ON" onclick="if(this.checked){t1.style.fontSize='18'} else{t1.style.fontSize='15'}">18px</p>
</form>

</body>

</html>
zhaoweiwei 2003-07-03
  • 打赏
  • 举报
回复
<html>

<head>

<title>New Page 1</title>
</head>

<body>

<form method="POST" action="">

<p><input type="text" name="t1" size="20">
<input type="checkbox" name="C1" value="ON" onclick="if(this.checked){t1.style.color='red'} else{t1.style.color='black'}">red 
<input type="checkbox" name="C2" value="ON">green</p>
</form>

</body>

</html>
fason 2003-07-03
  • 打赏
  • 举报
回复
http://www.csdn.net/cnshare/soft/5/5819.shtm
hahacc 2003-07-03
  • 打赏
  • 举报
回复
测试成功的代码:
<html>
<head>
<title>Untitled Document</title>
<script language="JavaScript">
function ddd(ss)
{
alert(ss)
if (ss=='color')
{
document.changestyle.text1.style.color=document.changestyle.color1.value;
return;
}
if (ss=='size')
{
document.changestyle.text1.style.fontSize=document.changestyle.size1.value;
return;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="changestyle" method="post" action="">
<input type="text" name="text1">
大小
<select name="size1" onchange="ddd('size')">
<option value="10px">10px</option>
<option value="11px">11px</option>
<option value="12px">12px</option>
<option value="13px">13px</option>
<option value="14px">14px</option>
</select>
颜色
<select name="color1" onchange="ddd('color')">
<option value="red">red</option>
<option value="blue">blue</option>
<option value="yellow">yellow</option>
</select>
</form>
</body>
</html>
zl13 2003-07-03
  • 打赏
  • 举报
回复
在文本框中显示是可以了,可为什么发布出去字体的颜色和大小却没有改变呢?
fason 2003-07-03
  • 打赏
  • 举报
回复
最好写成函数
<script language="JavaScript">
<!--
function chg(t,o,s,str){
var tt=document.frm.elements[t]
tt.style[s]=o.checked?str:''
}
//-->
</script>
<form name=frm>
<input type="text" name="test">
<input type="checkbox" onclick="chg('test',this,'fontSize','15pt')">
<input type="checkbox" onclick="chg('test',this,'color','red')">
<input type="checkbox" onclick="chg('test',this,'backgroundColor','yellow')">
</form>
kingdomzhf 2003-07-03
  • 打赏
  • 举报
回复
<html>
<body >


<input id=pp type=text value=exam>color:<input type=checkbox value=red onclick="if(this.checked==true) pp.style.color='red'; else pp.style.color='black' ">size:<input type=checkbox vlaue=20 onclick="if(this.checked==true) pp.style.fontSize='20'; else pp.style.fontSize='14'">
</body>
</html>
sw47 2003-07-03
  • 打赏
  • 举报
回复
<input id=xx type=checkbox onselect="sw()"><input id=ss>
<script>
function sw(){
if(xx.selected==true)
document.all.ss.style.color="red";
document.all.ss.style.fontSize="14pt";
}
else{
document.all.ss.style.color="black";
document.all.ss.style.fontSize="9pt";

}
</script>
Reker熊 2003-07-03
  • 打赏
  • 举报
回复
<input type=checkbox
onclick="txt1.style.color=(txt1.style.color=='#000000')?'#ff0000':'#000000';txt1.style.fontSize=(txt1.style.fontSize=='12pt')?'9pt':'12pt';">
<input type=text value="test" id=txt1 style="color:#000000;font-size:12pt;">
cnhxjtoa 2003-07-03
  • 打赏
  • 举报
回复
在文本框中编程实现,onFocus里设置它的color ,及大小
Reker熊 2003-07-03
  • 打赏
  • 举报
回复
<input type=checkbox
onclick="alert(txt1.style.fontSize);txt1.style.color=(txt1.style.color=='#000000')?'#ff0000':'#000000';txt1.style.fontSize=(txt1.style.fontSize=='12pt')?'9pt':'12pt';">
<input type=text value="test" id=txt1 style="color:#000000;font-size:12pt;">

87,987

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧