Javascript 将参数传递给svelte函数

Javascript 将参数传递给svelte函数,javascript,svelte,Javascript,Svelte,我是新来苗条的,所以请原谅我,如果这是显而易见的,但我已经尝试了我在其他帖子上看到的解决方案,似乎没有一个奏效 函数的调用如下所示: exampleFunction(“1”)}> 在JS中写为: function exampleFunction(id){ document.getElementById(`item-${id}`).classList.remove('hidden'); } “id”在函数中显示为未定义,因此我认为错误是从哪里传递过来的 提前谢谢你的帮助 检查这个屏幕截图,它工作

我是新来苗条的,所以请原谅我,如果这是显而易见的,但我已经尝试了我在其他帖子上看到的解决方案,似乎没有一个奏效

函数的调用如下所示:
exampleFunction(“1”)}>

在JS中写为:

function exampleFunction(id){
document.getElementById(`item-${id}`).classList.remove('hidden');
}
“id”在函数中显示为未定义,因此我认为错误是从哪里传递过来的


提前谢谢你的帮助

检查这个屏幕截图,它工作正常

在这里实时运行它:

代码:


函数示例函数(id){
log(“删除隐藏项之前”,document.getElementById(`item-${id}').classList);
document.getElementById(`item-${id}`).classList.remove(`hidden');
log(“删除隐藏项后”,document.getElementById(`item-${id}').classList);
}
示例函数(“1”)}>
在这里盘旋

在问题中显示您的example函数我在这里尝试过。它工作得很好。但在该示例中,我没有看到传递给函数的任何参数?不管怎样,谢谢你的帮助。就像我编辑的一样,让我在回答中告诉你谢谢,这非常有帮助-它确实有效!我原来的剧本有点不同,所以现在我已经修正了,一切都很好,再次感谢。欢迎兄弟。。。!
<script>

    function exampleFunction(id){
  console.log("Before removing hidden",document.getElementById(`item-${id}`).classList);
        document.getElementById(`item-${id}`).classList.remove('hidden');
      console.log("After removing hidden",document.getElementById(`item-${id}`).classList); 
  }
</script>

<button on:mouseover={() => exampleFunction("1")}>
    Hover here
</button>
<span id="item-1" class="active hidden"></span>