gpt4 book ai didi

dart - 如何使用Dart获得被点击元素的文本内容?

转载 作者:行者123 更新时间:2023-12-03 03:09:07 25 4
gpt4 key购买 nike

我正在使用dart开发应用程序,我想获得clicked元素的值。即:

HTML:

<div id="blah">Value!!</div>

镖:
void main(){
query("#blah").onClick.listen(showValue);
}

void showValue(Event e){
//Get #blah's innerHtml based on the Event(Something like e.target.innerHtml or e.target.value)
}

任何人?我知道如何在JS中执行此操作,但我想知道是否有在DART中执行此操作的方法!

编辑

感谢大家,我会变得更加清楚。我有一个循环,可动态生成9个元素并将其添加到容器中。

码:
var j = 0;
var optionsSquare = query("#optionsPanel");
while(j < 9){
DivElement minorSquare = new DivElement();

var minorSquareHeight = optionsSquare.clientHeight/3;
var minorSquareWidth = optionsSquare.clientWidth/3;

minorSquare
..attributes = {"class": "miniSugg"}
..style.width = (minorSquareWidth.round()-2).toString().concat("px")
..style.height = (minorSquareHeight.round()-2).toString().concat("px")
..style.float = "left"
..style.border = "1px solid"
..innerHtml = (j+1).toString();
..onClick.listen(showOptionsSquare);

optionsSquare.children.add(minorSquare);
j++;
}

如果我尝试使用@Pandian的方式,它可以工作,但我只能获取循环内最后一个元素的值。我想要的是以某种方式,跟踪单击的元素并获得其值(value)!

编辑2

伙计们,解决了!

如果有人需要此信息,我将在此处将代码作为存储库:
void showOptionsSquare(Event e){
window.location.hash = "#optionsPanel";
mainDiv.style.opacity = (0.2).toString();

DivElement clicked = e.target;
window.alert(clicked.innerHtml);
}

[]的

最佳答案

尝试如下...它将为您提供帮助...

DivElement div;

void showValue(){
window.alert(div.innerHTML);
}

void main() {
div = query('#blah');
div.on.click.add((Event e) => showValue());
}

关于dart - 如何使用Dart获得被点击元素的文本内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14942606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com