如何使文本输入框中的文字有颜色呢?

hiflash 2002-05-05 09:59:19
如何使文本输入框中的文字有颜色呢?

应该如何写JavaScript?

在线等待的。
...全文
61 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hiflash 2002-05-05
  • 打赏
  • 举报
回复
高手,我还要学的东西还很多呢。:)
孟子E章 2002-05-05
  • 打赏
  • 举报
回复
什么东西都可以改的:看看

<form name="form1" method="post" action="">
<p> (1)
<input type="radio" name="s1" value="radiobutton">
<input type="text" name="d1" onkeydown="test(this)">
</p>
<p> (2)
<input type="radio" name="s2" value="radiobutton">
<input type="text" name="d2" onkeydown="test(this)">
</p>
<p> (3)
<input type="radio" name="s3" value="radiobutton">
<input type="text" name="d3" onkeydown="test(this)">
</p>
<p> (4)
<input type="radio" name="s4" value="radiobutton">
<input type="text" name="d4" onkeydown="test(this)">
</p>
<p> (5)
<input type="radio" name="s5" value="radiobutton">
<input type="text" name="d5" onkeydown="test(this)">
</p>
</form>
<script>
function test(obj)
{
switch(window.event.keyCode)
{
case 49:
obj.value="优"
obj.style.color='#000000'
obj.style.fontWeight='normal'
event.returnValue=false
break;
case 50:
obj.value="良"
obj.style.color='#000000'
obj.style.fontWeight='normal'
event.returnValue=false
break;
case 51:
obj.value="中"
obj.style.color='#000000'
obj.style.fontWeight='normal'
event.returnValue=false
break;
case 52:
obj.value="及格"
obj.style.color='#000000'
obj.style.fontWeight='normal'
event.returnValue=false
break;
case 53:
obj.value="不及格"
obj.style.color='red'
obj.style.fontWeight='bold'
event.returnValue=false
break;
default:
event.returnValue=false
break;
}
if(event.keyCode == 38)
{
var id = window.event.srcElement.name
id = id.substr(1,1)
id = parseInt(id) - 1
if(id < 1) id = 5
eval("document.form1.d" + id + ".focus()")
}
if(event.keyCode == 40)
{
var id = window.event.srcElement.name
id = id.substr(1,1)
id = parseInt(id) + 1
if(id > 5) id = 1
eval("document.form1.d" + id + ".focus()")
}

}
</script>
孟子E章 2002-05-05
  • 打赏
  • 举报
回复

<form name="form1" method="post" action="">
<p> (1)
<input type="radio" name="s1" value="radiobutton">
<input type="text" name="d1" onkeydown="test(this)">
</p>
<p> (2)
<input type="radio" name="s2" value="radiobutton">
<input type="text" name="d2" onkeydown="test(this)">
</p>
<p> (3)
<input type="radio" name="s3" value="radiobutton">
<input type="text" name="d3" onkeydown="test(this)">
</p>
<p> (4)
<input type="radio" name="s4" value="radiobutton">
<input type="text" name="d4" onkeydown="test(this)">
</p>
<p> (5)
<input type="radio" name="s5" value="radiobutton">
<input type="text" name="d5" onkeydown="test(this)">
</p>
</form>
<script>
function test(obj)
{
switch(window.event.keyCode)
{
case 49:
obj.value="优"
obj.style.color='#000000'
event.returnValue=false
break;
case 50:
obj.value="良"
obj.style.color='#000000'
event.returnValue=false
break;
case 51:
obj.value="中"
obj.style.color='#000000'
event.returnValue=false
break;
case 52:
obj.value="及格"
obj.style.color='#000000'
event.returnValue=false
break;
case 53:
obj.value="不及格"
obj.style.color='red'
event.returnValue=false
break;
default:
event.returnValue=false
break;
}
if(event.keyCode == 38)
{
var id = window.event.srcElement.name
id = id.substr(1,1)
id = parseInt(id) - 1
if(id < 1) id = 5
eval("document.form1.d" + id + ".focus()")
}
if(event.keyCode == 40)
{
var id = window.event.srcElement.name
id = id.substr(1,1)
id = parseInt(id) + 1
if(id > 5) id = 1
eval("document.form1.d" + id + ".focus()")
}

}
</script>
孟子E章 2002-05-05
  • 打赏
  • 举报
回复

<form name="form1" method="post" action="">
<p> (1)
<input type="radio" name="s1" value="radiobutton">
<input type="text" name="d1" onkeydown="test(this)">
</p>
<p> (2)
<input type="radio" name="s2" value="radiobutton">
<input type="text" name="d2" onkeydown="test(this)">
</p>
<p> (3)
<input type="radio" name="s3" value="radiobutton">
<input type="text" name="d3" onkeydown="test(this)">
</p>
<p> (4)
<input type="radio" name="s4" value="radiobutton">
<input type="text" name="d4" onkeydown="test(this)">
</p>
<p> (5)
<input type="radio" name="s5" value="radiobutton">
<input type="text" name="d5" onkeydown="test(this)">
</p>
</form>
<script>
function test(obj)
{
switch(window.event.keyCode)
{
case 49:
obj.value="优"
obj.style.color='#000000'
event.returnValue=false
break;
case 50:
obj.value="良"
obj.style.color='#000000'
event.returnValue=false
break;
case 51:
obj.value="中"
obj.style.color='#000000'
event.returnValue=false
break;
case 52:
obj.value="及格"
obj.style.color='#000000'
event.returnValue=false
break;
case 53:
obj.value="不及格"
obj.style.color='red'
event.returnValue=false
break;
default:
event.returnValue=false
break;
}
if(event.keyCode == 38)
{
var id = window.event.srcElement.name
id = id.substr(1,1)
id = parseInt(id) - 1
if(id < 1) id = 5
eval("document.form1.d" + id + ".focus()")
}
if(event.keyCode == 40)
{
var id = window.event.srcElement.name
id = id.substr(1,1)
id = parseInt(id) + 1
if(id > 5) id = 1
eval("document.form1.d" + id + ".focus()")
}

}
</script>

87,996

社区成员

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

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