gpt4 book ai didi

javascript - 获取 polymer 中按钮的值

转载 作者:行者123 更新时间:2023-12-02 23:53:12 25 4
gpt4 key购买 nike

我正在尝试从按钮获取设置值,以便在我的函数中进一步处理它。

<template is="dom-if" if="[[Student.Absence]]">
<td><button class="defaultbutton" value="[[Student.studentnum]]"></button></td>
<td><button class="absentbutton" value="[[Student.studentnum]]" on-click="absenceHandler(this.value)"></button></td>
</template>




absenceHandler(studID){
let DummyStudents = this.get(['DummyStudents']);
console.log(studID);
alert(DummyStudents[1]);
}

我希望将值插入到我的函数中,但我得到的是:

监听器方法absenceHandler(this.value)未定义处理程序@ template-stamp.html:98(匿名)@templatize.html:160

最佳答案

不需要显式地将值发送给该方法。您可以按如下方式使其工作。

 <td><button class="absentbutton" value="[[Student.studentnum]]" on-click="absenceHandler"></button></td>


absenceHandler(e){
let studID = e.currentTarget.value;
let DummyStudents = this.get(['DummyStudents']);
console.log(studID);
alert(DummyStudents[1]);
}

关于javascript - 获取 polymer 中按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55549505/

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