2012-06-23 66 views
1

我有一個jQuery colorpicker,訪問者可以改變,我想弄清楚,我怎麼能通過他們輸入/選擇的任何值,以便我可以使用它作爲一個url查詢?獲取colorpicker輸入值並將其用於url查詢?

與我現在所擁有的一樣,您可以單擊色輪以在輸入中獲取十六進制代碼(例如#ffffff),或者只需將其輸入到輸入中,但我需要做的是將此價值,並鏈接到該網站的鏈接加上?color=#ffffff。我可以在顏色選擇器旁邊做一個鏈接來做到這一點,但我不知道如何讓它鏈接到訪客在顏色輸入中選擇的任何內容。

這裏是直播現場:http://www.brainbuzzmedia.com/themes/vertex/

下面是輸入HTML:

<input type="text" name="color-demo" id="color-demo" value="#ff0000" class="colorfield regular-text" data-hex="true" /> 

回答

2

這可以告訴你你的價值

alert(document.getElementById('color-demo').value); 

所以只需將其添加到您的鏈接:

<a href="" id="mylink">LINK</a> 

這樣的:

document.getElementById('mylink').href += document.getElementById('color-demo').value; 

JS代碼以上時調用的onChange用於彩色演示火災。例如,更改:

<input id="color-demo" class="colorfield regular-text" type="text" data-hex="true" value="#ff0000" name="color-demo"> 

<input id="color-demo" class="colorfield regular-text" type="text" data-hex="true" value="#ff0000" name="color-demo" onChange="myfun()"> 

,並創建myfun():

function myfun() 
{ 
document.getElementById('mylink').href += document.getElementById('color-demo').value; 
} 
+0

我可能沒看明白正確的,但這裏是我加的。在頭部添加「「然後我改變了輸入並添加了鏈接,所以它是:」LINK」 –

+0

「 brainbuzzmedia.com/themes/vertex/#ff0001所以請將myfun()更改爲如下所示: document.getElementById('mylink')。href + ='?color ='+ document.getElementById('color-demo') 。值; 這將創建一個更好的鏈接到index.php。然後,您需要處理index.php腳本中的新顏色 – Tom

+0

當我更改Firefox中的顏色​​時,我所看到的鏈接如下所示:http://www.brainbuzzmedia.com/themes/vertex/#fffffc#fffffc# fefffc#fefffc#f8fff8#f8fff8#f0fff4#f0fff4#e4fff3#e4fff3#e0fff7#e0fff7#dcfffc#dcfffc#d4ffff#d4ffff#d0fcff#d0fcff#ccf8ff#ccf8ff#ccf6ff#ccf6ff#c8f6ff#c8f6ff#c4f5ff#c4f5ff#c0f4ff# c0f4ff#bcf3ff#bcf3ff#b8f3ff#b8f3ff#acf6ff#acf6ff#a8f5ff#a8f5ff#9cf7ff#9cf7ff#88f5ff#88f5ff#80ffff#80ffff#78ffff#78ffff#74ffff#74ffff#70ffff#70ffff#6cffff#6cffff#68ffff#68ffff# 00fb96#00fb96#00ef9e#00ef9e#00e3a4#00e3a4#00e3ab#00e3ab#00dfa8#00dfa8#00dbb3#00dbb3#00dbba#00c4d7 –

相關問題