[英]how to add onclick event on @Html.RadioButtonFor?
我的单选按钮基本上有一个 model 值。
如何在@Html.RadioButtonFor
上添加点击事件处理程序?
@Html.RadioButtonFor(
model => model.AnswerResponse,
true,
new { id = "Yes"},
new { onclick = "alert('hi')"
})
@Html.RadioButtonFor
不包含四个 arguments。
如果您的按钮是唯一的并且有一个类(或通过 switch.to # 的 id),您可以执行以下操作:
const buttonThatIWantToCall = document.querySelector('.MyElementClass')
这将调用变量中的元素。 然后,您可以验证何时调用此变量中的元素:
buttonThatIWantToCall.addEventListener('click', Function);
然后,在 function 中做任何你想做的事情。
您可以使用onclick
html 属性传递 onClick 处理程序
@Html.RadioButtonFor(
model => model.AnswerResponse,
true,
new { @tabIndex = 1, @id = "Yes", @onclick="alert('hi')" }
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.