<div class="cell" data-row-id="1" data-column-id="1"></div>
<div class="cell" data-row-id="1" data-column-id="2"></div>
我必须修改 data-row-id = 1且 data-column-id = 2
的div的样式有可能吗?谢谢!
答案 0 :(得分:2)
您可以使用CSS
中的数据属性选择器执行此操作[data-row-id="1"] {
background-color: black;
}
答案 1 :(得分:2)
以下是您的问题的JavaScript解决方案。
document.querySelector('div[data-row-id="1"][data-column-id="2"]').style.color = 'green'
<div class="cell" data-row-id="1" data-column-id="1">something 1</div>
<div class="cell" data-row-id="1" data-column-id="2"> something 2</div>
以下是您的问题的CSS解决方案。
div[data-row-id="1"][data-column-id="2"] {
color:green;
}
<div class="cell" data-row-id="1" data-column-id="1">something 1</div>
<div class="cell" data-row-id="1" data-column-id="2"> something 2</div>
以下是解决问题的Jquery解决方案
$('div[data-row-id="1"][data-column-id="2"]').css('color', 'green');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cell" data-row-id="1" data-column-id="1">something 1</div>
<div class="cell" data-row-id="1" data-column-id="2"> something 2</div>
答案 2 :(得分:1)
您可以将data属性用作CSS选择器,例如:
0.001%
或使用Javascript:
function trackedProxy(name, val, _this){
let handler = {} // place your property traps here
let _privateObject = val
let _privateProxy = new Proxy(_privateObject, handler)
Object.defineProperty(_this, name, {
get: function() {
return _privateProxy;
},
set: function(value) {
console.log("object changed")
// Do something
return _privateObject = value;
}
});
}
//build one with invocation of the function, but do not set as equal to a var or you will have the same issue.
//**bad! - var a = trackedProxy('a',{keyOne: "one"},this)
trackedProxy('a',{ foo: "bar"}, this)
console.log(a)
//Proxy{ foo: "bar"}
a={keyOne: "one"}
//Object changed
console.log(a)
//Proxy{keyOne: "one"}
或使用jQuery:
.cell[data-column-id="2"] {
background: tomato;
}
.cell[data-row-id="1"][data-column-id="2"] {
background: green;
}
答案 3 :(得分:1)
您可以使用css属性选择器定位属性 https://www.w3schools.com/cssref/sel_attribute_value.asp
public class AsyncEnumerator<T>
{
private object _sync = new object();
private readonly Queue<T> _queue;
private readonly IEnumerable<T> _enumerable;
public AsyncEnumerator(IEnumerable<T> enumerable)
{
_enumerable = enumerable;
_queue = new Queue<T>();
}
/// <summary>
/// Start getting results when requested the firstTime
/// </summary>
private bool _startFlag;
public async Task<bool> MoveNextAsync()
{
if (_finished)
{
return false;
}
if (!_startFlag)
{
_startFlag = true;
SetResultsAsync();
}
if (_queue.Count > 0)
{
Current = _queue.Dequeue();
return true;
}
//What here?
return await Task.Run(()=> true);
}
private T _current;
public T Current
{
get
{
lock (_sync)
{
return _current;
}
}
private set { _current = value; }
}
private bool _finished;
private async Task SetResultsAsync()
{
IEnumerator<T> enumerator = _enumerable.GetEnumerator();
bool moveNext = await Task.Run(() => enumerator.MoveNext());
while (moveNext)
{
_queue.Enqueue(enumerator.Current);
moveNext = await Task.Run(() => enumerator.MoveNext());
}
_finished = true;
}
}