for循环生成的button怎么修改里面的文字?
我用for循环生成了很多个button,
我想点击单个button后,修改该button的文字。
请问这个要怎么做呢?


我给每个button,绑定了不一样的id,
要怎么根据id,来修改这个button的class、内部文字呢?
1 回复
绑定的话用data-id,事件的话加在他们父级比较好一点,可以减少当前页面的事件数,当然给每个button加也是可以的,取值的话如果加在父组件用e.target.dataset.id取,如果是子组件用e.记不住中间这个单词了.dataset.id,,,,你打印一下e就可以了