return $r; } /** * @param int $page 页数 * @param int $pagesize 每页显示数量 * @return mixed */ function link_find($page = 1, $pagesize = 100) { $arr = link__find($cond = array(), array('rank' => -1), $page, $pagesize); return $arr; } /** * @param $id * @return bool 返回FALSE失败 TRUE成功 */ function link_delete($id) { if (empty($id)) return FALSE; $r = link__delete(array('id' => $id)); link_delete_cache(); return $r; } //--------------------------kv + cache-------------------------- /** * @return mixed 返回全部友情链接 */ function link_get($page = 1, $pagesize = 100) { $g_link = website_get('friends_link'); if (empty($g_link)) { $g_link = link_find($page, $pagesize); $g_link AND website_set('friends_link', $g_link); } return $g_link; } // delete kv and cache function link_delete_cache() { website_set('friends_link', ''); return TRUE; } ?>javascript - How to get the new color value from Input Color after choosing it? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get the new color value from Input Color after choosing it? - Stack Overflow

programmeradmin13浏览0评论

I use Input Color to change the color of the text in a table cell.

I can select the cell, click on the color button, select the color and press enter (on Chrome).

My problem is that the color changes only after I press again on the color button (and the window open again..).

How to change/get the value of the element after selecting the new color without clicking on it again ?

Is this related to the EventListener I use for the Input Color ?

I need to use JavaScript for this, no jQuery.

I use Input Color to change the color of the text in a table cell.

I can select the cell, click on the color button, select the color and press enter (on Chrome).

My problem is that the color changes only after I press again on the color button (and the window open again..).

How to change/get the value of the element after selecting the new color without clicking on it again ?

Is this related to the EventListener I use for the Input Color ?

I need to use JavaScript for this, no jQuery.

Share Improve this question edited Apr 1, 2016 at 10:37 New 6711 gold badge12 silver badges21 bronze badges asked Apr 1, 2016 at 10:07 user3450862user3450862 5501 gold badge9 silver badges25 bronze badges 4
  • How about change listener ? Edit: <input type="color" name="favcolor" value="#ff0000" onchange='alert()'> – Rayon Commented Apr 1, 2016 at 10:07
  • @RayonDabre I added 'this.inputC.onchange='alert()';' and tried to see if it detects the value changes with 'function alert() { alert("Changed");}'. No detection at all. The value changes only after I close the color chooser and I click again the button. – user3450862 Commented Apr 1, 2016 at 10:25
  • better with some code JS fiddle – Joy Biswas Commented Apr 1, 2016 at 10:25
  • Can you share executable demo/snippet or JSFiddle ? – Rayon Commented Apr 1, 2016 at 10:25
Add a ment  | 

2 Answers 2

Reset to default 3

You can get input value with onchange event.

jQuery('#color').on('change',function(){
	jQuery('#choosen-color').text(jQuery(this).val());
});
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="color" id="color">
<div id="choosen-color"></div>

UPDATE

document.getElementById('color').onchange=function(){
	// do whatever you want with value
  alert(this.value);
}
<input type="color" id="color">

Try This code it is work foe me..!

This code is pure JavaScript not use jquery..!

Use This Code And Enjoy...

var color1= document.getElementById("color1");
var rescolor1= document.getElementById("res_color1");
  color1.addEventListener("input", function() {
    res_color1.innerHTML = color1.value;
  }, false); 
var color2= document.getElementById("color2");
var res_text_color = document.getElementById("res_color2");
  color2.addEventListener("input", function() {
    res_color2.innerHTML = color2.value;
  }, false); 
// mmm.... is it an Opera bug? the manual input doesn't fire the input event type. (works just like change)
    color 1: <input type="color" name="color1" id ="color1" required=""> <span id="res_color1"></span><br><br>
    color 2: <input type="color" name="color2" id ="color2" required=""> <span id="res_color2"></span><br><br>

发布评论

评论列表(0)

  1. 暂无评论