使用javascript更改文本框文本颜色

时间:2015-10-23 16:22:38

标签: javascript html css textbox

我有一个文本框。当我点击这个时我想用javsacript改变文本颜色样式。之前我成功了。当有人点击文本框文本框时,当模糊文本框变成旧版本时清除内部。这段代码现在适用于我

This is doSmth3() in A...

但是,当有人专注于此时,我想更改文本颜色和文本框边框大小。代码无法正常工作

<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...'}"/> 

3 个答案:

答案 0 :(得分:2)

1.在您的文档中包含jQuery库。

2.包括这个脚本:

$(document).ready(function(){
   $('#kullanici_adi_text').focus(function(){
       $(this).css('color', 'red');
   }).focusout(function(){
       $(this).css('color', 'black');
   });
});

答案 1 :(得分:2)

您应该使用颜色配额:

<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代码。

答案 2 :(得分:1)

这会起作用 <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>
相关问题