JavaScript代码重构用于刺激控制器
如何重构JS代码:
const fileInput = document.getElementById('input');
const p = document.querySelector('p');
fileInput.onchange = () => {
const selectedFiles = [...fileInput.files];
p.textContent = selectedFiles.map(s => s.size).join(', ');
}
使其在铁路刺激中起作用? 我在JS方面几乎没有经验,并且希望有一个或两个在刺激控制器中实现JS代码的示例,因此我有材料可以自己重构其他情况。 非常感谢。
How to refactor JS code like this:
const fileInput = document.getElementById('input');
const p = document.querySelector('p');
fileInput.onchange = () => {
const selectedFiles = [...fileInput.files];
p.textContent = selectedFiles.map(s => s.size).join(', ');
}
to make it work in rail's Stimulus?
I have very little experience with JS and want to have one or two examples of implementing JS code in Stimulus controllers, so I have material to refactor other cases on my own.
Much thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能的解决方案:
One possible solution: