获取colorpicker输入值并将其用于url查询?
问题描述:
我有一个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" />
答
这可以告诉你你的价值
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;
}
我可能没看明白正确的,但这里是我加的。在头部添加““然后我改变了输入并添加了链接,所以它是:”LINK” –
“ brainbuzzmedia.com/themes/vertex/#ff0001所以请将myfun()更改为如下所示: document.getElementById('mylink')。href + ='?color ='+ document.getElementById('color-demo') 。值; 这将创建一个更好的链接到index.php。然后,您需要处理index.php脚本中的新颜色 – Tom
当我更改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 –