gpt4 book ai didi

javascript - 如何在 Angular 4 中获取点击按钮的值

转载 作者:行者123 更新时间:2023-11-30 11:34:21 25 4
gpt4 key购买 nike

我有 4 个按钮,每个按钮都有唯一的值。我在控制台日志中使用当前代码未定义。

HTML

<button type="submit" class="parcel-btn weight-option" value="25" (click)="onItemSelector()">
<button type="submit" class="parcel-btn weight-option" value="50" (click)="onItemSelector()">
<button type="submit" class="parcel-btn weight-option" value="250" (click)="onItemSelector()">
<button type="submit" class="parcel-btn weight-option" value="100" (click)="onItemSelector()">

typescript

onItemSelector() {
const weightSelector = this.elm.nativeElement.querySelectorAll('.weight-option').value;
console.log(weightSelector);
}

最佳答案

试试这个

将值传递给 onItemSelector 函数

   <button type="submit" class="parcel-btn weight-option" (click)="onItemSelector(25)">

获取ts中的值

onItemSelector(value :any) {
console.log(value);
}

关于javascript - 如何在 Angular 4 中获取点击按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45071436/

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