如何间接引用 javascript 对象?
认为:
<div id="foo" data-munchy="bar" data-crunchy="baz">FooBar</div>
<script>
document.getElementById("foo").onclick = function() {
tempVariable = 'munchy';
console.log(this.dataset.tempVariable);
}
</script>
我怎样才能访问this.dataset.{someVariable}
?在这种情况下,this.dataset.tempVariable
只能使用eval
orwindow
吗?