将参数传递给 svelte 函数

Passing parameters to svelte function

我是 Svelte 的新手,如果这很明显,请原谅我,但我已经尝试了我在其他帖子中看到的解决方案并且 none 似乎有效。

函数调用如下: <div on:mouseover={() => exampleFunction("1")}>

在JS中是这样写的:

function exampleFunction(id){
document.getElementById(`item-${id}`).classList.remove('hidden');
}

'id' 在函数中显示为未定义,所以我认为错误是从哪里传递的。

提前感谢您的帮助!

查看此屏幕截图,它正在运行

运行 它住在这里:https://svelte.dev/repl/501e5d478bbe4bc5a5e9f6a67523d080?version=3.16.0

代码:

<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>