JS点击图片指定对象变色两种方法

用JS写的修改图片颜色值的工具第一步 立即下载

要求:点击上面的颜色实现下面的图像变成相同的颜色

 

难点:对于js函数的this对象不太清楚如何传递

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>changeColor</title>
    <style>
        td {
            width: 50px;
            height: 50px;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <td style="background-color: #2f74ff"></td>
            <td style="background-color: yellow"></td>
            <td style="background-color: pink"></td>
            <td style="background-color: red"></td>
            <td style="background-color: green"></td>
            <td style="background-color: grey"></td>
            <td style="background-color: chocolate"></td>
        </tr>
    </table>
    <table id="square" style="width: 500px; height: 500px; background-color: lightblue">

    </table>
    <script>
        function changColor(){
            console.log(this)
            var bc = this.style.backgroundColor
            var target = document.getElementById('square')
            target.style.backgroundColor = bc
        }
        var tot = document.querySelectorAll('table tr td')
        for (const obj of tot) {
            obj.onclick = changColor
        }
    </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>changeColor</title>
    <style>
        td {
            width: 50px;
            height: 50px;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <td style="background-color: #2f74ff" onclick="changColor(this)"></td>
            <td style="background-color: yellow" onclick="changColor(this)"></td>
            <td style="background-color: pink" onclick="changColor(this)"></td>
            <td style="background-color: red" onclick="changColor(this)"></td>
            <td style="background-color: green" onclick="changColor(this)"></td>
            <td style="background-color: grey" onclick="changColor(this)"></td>
            <td style="background-color: chocolate" onclick="changColor(this)"></td>
        </tr>
    </table>
    <table id="square" style="width: 500px; height: 500px; background-color: lightblue">

    </table>
    <script>
        function changColor(obj){
            console.log(obj)
            var bc = obj.style.backgroundColor
            var target = document.getElementById('square')
            target.style.backgroundColor = bc
        }
    </script>
</body>
</html>

 

别再折腾SNAP了!ENVI 5.6.0 直接拖拽打开Sentinel-2 L2A数据的正确姿势 本文详细介绍了ENVI 5.6.0直接处理Sentinel-2 L2A数据的高效方法,无需通过SNAP进行繁琐的重采样预处理。通过直接拖拽XML文件,用户可以快速加载不同分辨率的波段数据,显著提升工作效率。文章还对比了直接打开与SNAP重采样流程的优劣,并提供了常见问题解决方案和高级应用技巧。 阅读详情

相关推荐

【MCU开发规范】:车载MCU开发规范

车载MCU开发规范

1056

canvas+javascript实现点击更改图片中指定部位的颜色(将近似的颜色值变更为自定义的颜色)

javascript+canvas实现点击更改图片颜色

xioxi 1748

【S32K】S32K144入门笔记(3) SPI(lpspi组件)

0. 引言 与第二篇can对应,第三篇本来想写lin的,毕竟都是车身上常用的总线。但是lin比较麻烦,所以先拖后一下,先把SPI记录一下。 SPI在我们的系统架构中是S32K和ADAS之间做数据传输用的,毕竟速率够高,数据量能传的比较大。 1. 准备 1.1 SPI基础知识 1.2 开发环境 1.2.1 软件开发环境 1.2.2 硬件环境 SPI 2. Demo ...

YoYo的桃子树 2万+

js实现按钮点击变色,其他的按钮恢复默认颜色

JavaScript实现按钮点击变色,其他的按钮恢复默认颜色,则需通过循环实现,当有按钮点击的时候,先将所有的按钮的颜色,更改为空,然后在针对,鼠标点击的相应的按钮,进行更改按钮颜色;onclick实现按钮点击后的操作;...

异想实验室|Arduion|ESP8266|Micro Python| 1万+

洛谷 P5736 【深基7.例2】质数筛

题目描述 输入 n(n\le100)n(n≤100) 个不大于 100000 的整数。要求全部储存在数组中,去除掉不是质数的数字,依次输出剩余的质数。 输入格式 无 输出格式 无 输入输出样例 输入 #1 复制 5 3 4 5 6 7 输出 #1 复制 3 5 7 板子题,使用一下线性筛 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using n

qq_37978559的博客 1121

手把手教你为TI C2000 DSP(如28335)编写BootLoader:从Flash擦写到程序跳转的完整避坑指南

本文详细介绍了为TI C2000 DSP(如28335)编写BootLoader的完整流程,从Flash擦写到程序跳转的避坑指南。涵盖环境搭建、Flash操作安全实践、中断向量表管理、链接文件调整、通讯协议设计及量产化部署策略,帮助开发者构建工业级可靠的BootLoader系统,提升设备维护效率。

weixin_30825581的博客 431

通过使用简单的JavaScript的效果实现点击按钮区域变色,并记录变化次数

通过html,css,js代码实现点击按钮,标签区域变化,并且记录颜色变化的次数,通过js代码实现不断变化效果,用到了函数和点击事件以及其他的js知识

小杨的博客 5187

YOLOv11 改进 - 即插即用 | PST金字塔稀疏Transformer:粗粒度到细粒度推理优化特征提取,提升复杂场景适应性

本文介绍了金字塔稀疏 Transformer(PST)与 YOLOv11 的结合。主流基于注意力的特征融合方法计算复杂度高、实现难度大,作者提出 PST 模块,融合粗到细令牌选择与共享注意力参数机制,在保留空间细节的同时降低计算量。该模块通过层级化注意力机制、动态令牌选择与参数共享,实现高效多尺度特征融合

魔改工程师的博客 831

js改变图片颜色

在中,若想对元素的颜色进行改变,需要使用属性,而通过标签引入的图片却没有办法使用该属性,此时,提供了一个属性对图片加滤镜。

qq_38980678的博客 1671

光学系统仿真软件:OSLO_(13).衍射光学元件设计v1

目标函数是设计DOE的关键步骤之一。目标函数可以是一个具体的光强分布,也可以是一个特定的波前形状。在仿真软件中,目标函数通常用数学表达式或数据文件来定义。假设我们需要设计一个二元相位掩模,使其在特定位置生成三个焦点。我们可以定义一个目标函数来描述这三个焦点的光强分布。# 定义目标函数"""定义一个多焦点目标函数:param x: 横坐标:param y: 纵坐标:param z1: 第一个焦点的深度:param z2: 第二个焦点的深度:param z3: 第三个焦点的深度。

kkchenjj的博客 1006

【即插即用模块】Transformer篇 | CVPR 2025 | SADA:多尺度+可变形采样,完美替换自注意力实现涨点!

文章摘要 本文提出了一种尺度自适应可变形注意力模块(SADA),用于处理图像修复中的结构化伪影问题。SADA通过多尺度多头机制捕获远程依赖关系,并引入可变形采样偏移来有效处理非均匀空间分布的模式。该模块适用于底层视觉任务,可替代ViT自注意力,实验证明能显著提升性能。代码已开源,支持即插即用集成。 核心特点: 多尺度头适应不同大小的重复模式 可变形偏移优化非均匀分布采样 轻量级设计,易于集成到现有架构 适用场景:图像去噪、超分辨率等底层视觉任务。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1436

使用js实现单击按钮,让他改变颜色

按钮1按钮2按钮3按钮4按钮5按钮

weixin_70079360的博客 4507

AutoSAR配置与实践(实践篇)11.1 如何通过IPDU分组控制报文收发

注意这个新增的action其实是一个用户回调函数,在函数中进行配置字的判断,即可完成用户条件的判断(TRUE/FALSE),注意用户条件是用户封装的函数,用于输入给后续的逻辑判断和rule。进行PDU的拆分后,根据配置字可以选择PDU是否使能了。PDU组拆分后可分为常规PDU组和可配PDU组(新增),诊断一方面按原有逻辑控制常规PDU组,另一方面控制新的可配PDU组。举例说明,诊断场景:使能,配置字满足,则用户条件为TURE,表示期望使能可配PDU组(诊断禁止服务场景类似方式,在此不再列举)。

nihaoljq2010的博客 838

JavaScript——点击按钮使div变色

head> meta charset="UTF-8"> title>点击按钮使div变色title> style> div{ border:1px solid white; width:200px; height:200px; background-color:#7f7f7f; } /style> head> body> div id="one">div>

Chenbaby_的博客 1万+

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

有多个按钮,点击一个变色,点击另一个变色,原来的恢复颜色的方法

之前用到网上说的fouce也可行,但是失去焦点后,点击别处按钮也会恢复颜色,所以这样也行不通。后来找了好久,这个方法终于行的通。 html代码: 我是在table中加的按钮submit。 <table> <tr> <td> <input class="fla...

3060

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

vue中怎么点击修改文字_在Vue中如何实现点击后文字变色

下面我就为大家分享一篇Vue实现点击后文字变色切换方法,具有很好的参考价值,希望对大家有所帮助。这里用文字举例,图片切换的原理也是一样的大概思路是:用两个class相同的span分别是切换前后的文字,class相同主要是为了变换前后的文字位置相同。然后用click事件控制它们的显隐。代码如下:HTML:回复回复JS:data(){return {showCommentInput = false,}...

weixin_39873456的博客 2377

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

css 图标点击变色,纯CSS实现小图标变色的一些研究

by zhangxinxu from www.zhangxinxu.com/wordpress/?…本文可全文转载,个人网站无需授权,只要保留原作者、出处以及文中链接即可,任何网站均可摘要聚合,商用请联系授权。一、把Canvas图片作为CSS背景图片CSS Paint API可以简单理解为(实际不能等同)把Canvas画布作为普通元素的背景图片。也就是CSS的background-image就是一...

weixin_29959549的博客 1445

微信小程序图标点击后变色并跳转页面

至今不知道怎么上传动图的我只能用嘴描述了…..在微信小程序里,希望出现点击图标图标先变色然后跳转到指定页面。 首先需要准备两张图标的图片,一张是未点击状态,一张是点击后的状态。 index.wxml &amp;amp;lt;view&amp;amp;gt; &amp;amp;lt;image catchtap='change' wx:if=&amp;quot;{{click}}&amp;quot; src='/icon/1.png'&a

weixin_43028221的博客 1万+

javascript核心03(按钮变色 百度换肤 表格隔行变色效果)

1.按钮变色(排他算法) <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title&...

weixin_43321726的博客 303

Vue实现点击后文字变色切换

Vue实现点击后文字变色切换这里用文字举例,图片切换的原理也是一样的大概思路是:用两个class相同的span分别是切换前后的文字,class相同主要是为了变换前后的文字位置相同。然后用click事件控制它们的显隐。代码如下:HTML:<span class="response" v-show="!showCommentInput" @click="showCommentInput = !showC

HaiJing1995的博客 2万+

点击开关按钮,js实现电灯开关效果

js实现开关灯效果

qq_53983648的博客 6591

鼠标点击表格行背景变色 js

<HTML><HEAD><TITLE>鼠标点击表格行背景变色</TITLE><style> .MouseOverClick {background-color: #D9EFFD} .MouseOutWhite {background-color: #FFFFFF}</style>...

weixin_30640769的博客 481

背景色自动切换html,JavaScript实现网页背景自动变色

JavaScript实现网页背景自动变色,自己变换颜色,设定时间和颜色值即可,在你设定的颜色值、一定时间内自动切换网页背景颜色。/p>"http://www.w3.org/TR/html4/loose.dtd">背景自动变色背景自动变色var Arraycolor=new Array("#00FF66","#FFFF99","#99CCFF","#FFCCFF","#FFCC99","...

weixin_39905816的博客 2870

android 点击爱心变色,小程序学习(一):点击爱心变色最简单的事件实现

最近在学习小程序,想通过写文章来记录自己的学习历程,希望能做到每周都写……如何绑定一个事件微信小程序中,绑定事件要在标签内写入这两段代码:bindtap="fnActive"data-favourite = "{{isLike}}"复制代码bindtap 有两层含义,tap 代表这是一个点击事件,bind 代表这个事件能被监听,同时 bindtap 是一个缩写,bind:tap 才是它完全的写法。...

weixin_32259717的博客 484

html + jquery地图点位点击变色

地图用图片展示,jquery实现相关的点击出现信息弹窗的操作

include_computer的博客 1277

php js点击变色,JS实现按钮点击颜色切换功能示例分享

本文主要介绍了JS实现的按钮点击颜色切换功能,涉及js鼠标事件响应及页面元素属性动态操作相关实现技巧,需要的朋友可以参考下,希望能帮助到大家。先来看看运行效果:具体代码如下:www.jb51.net 点击切换按钮颜色按钮1按钮2按钮3//设置背景颜色//如果设置参数函数会节省函数数量吧//设置flag+参数函数flag = "btn1";function btn1(){document.getEl...

weixin_29047545的博客 788
上一篇: 小白Git极简9步入门
zlq7777
博客等级 码龄5年 13粉丝 55原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值