input type color

<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.

1
2
3
4
var colorWell;
var defaultColor = "#0000ff";
 
window.addEventListener("load", startup, false);

Initialization

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

1
2
3
4
5
6
7
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());
        });

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(380)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2018-10-31 Could not load file or assembly 'MyAssembly.XmlSerializers
2017-10-31 如何编译dotnet core
2014-10-31 第7章 调试和错误处理 7.1.1 VS中的调试
2014-10-31 markdown的语法说明
2014-10-31 在Github上搭建博客
点击右上角即可分享
微信分享提示