2011-10-28 144 views
1

我使用farbtastic color picker和工作正常,但現在我需要改變使用這個插件的文字顏色。Jquery顏色選擇器來改變文字顏色

這是我現在有:

http://jsfiddle.net/g2hZy/15/

這是我的代碼:

有了這個文本的顏色沒有改變,並沒有顯示我的十六進制值了。

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#colorpicker').farbtastic(function (color) { 
      $("#colorpicker").style("color", color); 
     }); 

    }); 
</script> 

文本輸入控件:

<input type="text" id="color" name="color" value="#123456" /> 

顏色選擇器的佔位符:

<div id="colorpicker"></div> 

這是我的文字輸入:

<input id="Text1" type="text" /> 

現在,如果我寫的東西和改變顏色選擇器的顏色我需要更改t他從「Text1」輸入中輸入forecolor。

回答

6

這似乎工作:

$(document).ready(function() { 
    $('#colorpicker').farbtastic(function(color) { 
     // sets the color for both the 'color' and 'Text1' inputs 
     $("#color, #Text1").css("color", color); 
     // updates the 'color' input to the currently-selected color 
     $("#color").val(color); 
    }); 

}); 

JS Fiddle demo

+0

感謝大衛救了這麼多的時間對我來說,我真的很感謝你的幫助。 – coder

+0

@ user944919,僅供參考 - 此解決方案/演示在Safari中不起作用。 – Sparky

+0

好吧沒有probs我會盡力管理,但我需要知道如何給文本的基本顏色。並感謝你讓我知道:) – coder

1

要更改文本顏色,你也可以使用這樣的事情 -

<input type="text" name="text_color" id="text_color" value=""/> 

<div id="text_picker"></div> 

$('#text_picker').farbtastic(ChangeTextColor); 

function ChangeTextColor(color) 
{ 
    $('#text_color').css('color', color); // will change the color of text 
    $('#text_color').val(color);  // will change the hex value of textbox 
}