我目前正在尝试通过 cshtml 文件内的表单调用 javascript 函数。表单中会有一个文本框,用于接收来自用户的字符串和“发送”按钮,用于将字符串发送到 javascript 函数。
表单脚本:
@using (Html.BeginForm("SearchStreet", "CustomerInformation", FormMethod.Get, new { @class = "form-inline" }))
{
<input type="hidden" name="CustId" value="@ViewBag.CustId" />
<input type="hidden" name="AddressId" value="@ViewBag.AddressId" />
<div class="form-group">
<label for="street">Street Name</label>
@Html.TextBox("street", null, htmlAttributes: new { @class = "form-control" })
</div>
<div class="form-group">
<label></label>
<input type="submit" value="Send" class="form-control btn btn-default" />
</div>
}
如何将字符串发送到特定的Javascript函数? 谢谢。
最佳答案
@using (Html.BeginForm("SearchStreet", "CustomerInformation", FormMethod.Get, new { @class = "form-inline" }))
{
<input type="hidden" name="CustId" value="@ViewBag.CustId" />
<input type="hidden" name="AddressId" value="@ViewBag.AddressId" />
<div class="form-group">
<label for="street">Street Name</label>
@Html.TextBox("street", null, htmlAttributes: new { @class = "form-control" })
</div>
<div class="form-group">
<label></label>
<input type="submit" onclick="sendValue();" value="Send" class="form-control btn btn-default" />
</div>
}
<script type="text/javascript">
function sendValue(){
var element = document.getElementById(street);
//Get value by element.value, rest you know what to do
}
关于javascript - 如何将值从表单发送到 cshtml 中的 Javascript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43223190/