使用javascript更改文本框的文本颜色
Change textbox text color with javascript
我有一个文本框。当我点击这个时,我想用javascript改变文本颜色样式。在此之前,我成功地制作了这个。当有人点击文本框时,文本框内部清除,文本框变成旧版本模糊。这段代码现在为我工作了
<input id="kullanici_adi_text" type="text" name="kullanici_adi_text" value="Kullanıcı İsmini Giriniz..." onfocus="if(this.value=='Kullanıcı İsmini Giriniz...') {this.value='';} onblur="if(this.value==''){this.value='Kullanıcı İsmini Giriniz...'}"/>
但我想改变文本的颜色也和文本框的边界大小,当有人关注这个。代码不工作
<input id="kullanici_adi_text" type="text" name="kullanici_adi_text" value="Kullanıcı İsmini Giriniz..." onfocus="if(this.value=='Kullanıcı İsmini Giriniz...') {this.value=''; document.getElementById('kullanici_adi_text').style.color = 'blue';}" onblur="if(this.value==''){this.value='Kullanıcı İsmini Giriniz...'; document.getElementById('kullanici_adi_text').style.color = #fff; }"/>
您应该使用颜色配额:
<input id="kullanici_adi_text" type="text"
name="kullanici_adi_text"
value="Kullanıcı İsmini Giriniz..."
onfocus="if(this.value=='Kullanıcı İsmini Giriniz...')
{this.value='';
this.style.color = 'blue';}"
onblur="if(this.value=='')
{this.value='Kullanıcı İsmini Giriniz...';
this.style.color = '#ff0000';}"/>
作为一个建议,最好将javascript代码与标记分开。
可以<input id="kullanici_adi_text" type="text" onfocus="myFunction()">
<script>
function myFunction() {
document.getElementById("kullanici_adi_text").style.color = "#ff0000";
document.getElementById("kullanici_adi_text").style.color = "magenta";
document.getElementById("kullanici_adi_text").style.color = "blue";
document.getElementById("kullanici_adi_text").style.color = "lightblue";
}
</script>
1。在你的文档中包含jQuery库
2。包括这个脚本:
$(document).ready(function(){
$('#kullanici_adi_text').focus(function(){
$(this).css('color', 'red');
}).focusout(function(){
$(this).css('color', 'black');
});
});
相关文章:
- 使用CSS/JavaScript更改剑道图工具提示文本颜色
- mouseover和mouseleave文本颜色更改在指令链接中不起作用
- 如何在flash html5画布项目中动态更改文本颜色
- 使用JavaScript淡化文本颜色
- 使用Javascript切换文本颜色
- 我可以使用jqgrid的oncellselect事件根据单元格内容将文本颜色更改为蓝色吗
- 使用jquery更改文本颜色和大小
- 如何使用javascript更改
前色/文本颜色以及boder颜色 - Extjs 树 如何更改子元素的文本颜色
- 选项选定的文本颜色
- JQuery:悬停时文本颜色切换
- 根据覆盖的背景区域的亮度更改文本颜色
- 根据类型更改 jstree 节点文本颜色
- 文本颜色的随机色调不起作用
- 如何在高亮显示时更改文本颜色
- 使用CSS或SVG设置与背景颜色匹配的文本颜色的动画
- Chart.js文本颜色
- 如何更改chardin.js中的文本颜色和样式
- 更改javascript代码段背景和文本颜色
- 如何在安卓网页中更改背景和文本颜色