简体   繁体   中英

How do I use jQuery to return the current state of my div?

var div = document.querySelector('#myDiv')
div.dataset.color = 0;
div.addEventListener('click',()=>{
div.dataset.color = parseInt(div.dataset.color)+10;
var c = (div.dataset.color%256)*100;
div.style.background = 'rgb(0,'+c+',0)';
});

#myDiv {
width: 200px;
height: 200px;
background: #000000;
}

<div id="myDiv"></div>

If I am using this code for individuals to choose a color, how do I use jquery to return the current state of the color picker? Meaning, if a person was clicking through until they found the color they wanted, what can i do to log the selection that they decide on? Is there a button I can use to select the color and then output that selection into an excel file?

您将要在jQuery中选择div并使用css函数来检索您要查找的值。

$("#myDiv").css("background-color");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM