码迷,mamicode.com
首页 > 其他好文 > 详细

input type color

时间:2019-10-31 10:38:26      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:get   this   eal   cal   tps   word   tor   depend   def   

<input type="color">

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color

JavaScript

First, there‘s some setup. Here we establish some variables, setting up a variable that contains the color we‘ll set the color well to when we first load up, and then setting up a load handler to do the main startup work once the page is fully loaded.

var colorWell;
var defaultColor = "#0000ff";

window.addEventListener("load", startup, false);

Initialization

Once the page is loaded, our load event handler, startup(), is called:

function startup() {
  colorWell = document.querySelector("#colorWell");
  colorWell.value = defaultColor;
  colorWell.addEventListener("input", updateFirst, false);
  colorWell.addEventListener("change", updateAll, false);
  colorWell.select();
}

This gets a reference to the color <input> element in a variable called colorWell, then sets the color input‘s value to the value in defaultColor. Then the color input‘s input event is set up to call our updateFirst() function, and the change event is set to call updateAll(). These are both seen below.

Finally, we call select() to select the text content of the color input if the control is implemented as a text field (this has no effect if a color picker interface is provided instead).

 

使用JQuery

 /*color*/
    $(‘[type=color]‘).on(‘change‘, function () {
        var block = $(this).parents(‘.blockquote‘);
        block.find(‘.br-ccc‘).css(‘background-color‘, $(this).val());
        block.find(‘[type=text]‘).val($(this).val());        
    });

 

 $(‘#nav-page-styling [name]‘).each(function () {
            var value = page.model.Page[$(this).attr(‘name‘)];
            $(this).val(value);
            $(this).parents(‘.blockquote‘).find(‘.br-ccc‘).css(‘background-color‘, $(this).val());
        });

 

input type color

标签:get   this   eal   cal   tps   word   tor   depend   def   

原文地址:https://www.cnblogs.com/chucklu/p/11769683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!