如何使用 Razor 更改隐藏字段的值,然后调用 JavaScript 函数 alert("hello") onchange 事件。
由于某种原因,下面的代码不起作用......
<input id="trigger" name="trigger" type="hidden" value="6" onchange="alert("hello") />
@{
var hiddenfieldvalue = @Html.Hidden("trigger", "5"); // it would be better to retrieve the value at first which is 6, rather than assigning it to 5.
// the code below should cause the hidden field value to change, which will then call alert("hello")
if(hiddenfieldvalue.ToString() == "2")
@Html.Hidden("value","3");
else
@Html.Hidden("value", "2");
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add Numbers</title>
<meta charset="utf-8" />
<style type="text/css">
body {background-color: beige; font-family: Verdana, Arial;
margin: 50px; }
form {padding: 10px; border-style: solid; width: 250px;}
</style>
</head>
<body> </body>
</html>