当我按下具有onclick方法“ doSomething()”的按钮时,它将执行doSomething()方法,然后显示noMethoderror错误。它尝试去some_path。我不希望该按钮转到some_path-我只希望它执行javascript函数。如何解决呢?
= form_for(:set, url: some_path) do |form|
h1 Create Something
button onclick="dosomething()" Add something
div
= form.label :some_text
= form.text_field :some_text
div
= form.submit
= javascript_include_tag 'application'
将按钮的类型更改为type =“ button”即可。默认情况下,slim将其解析为提交按钮。
button type="button"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句