Javascript 如何在单击按钮时调用JS函数,然后在调用时打开弹出窗口?
我正在使用JS函数向控制器发送值我想在向控制器提交值之前显示一个弹出窗口,如果按下弹出窗口确认按钮,则保存值,然后将值发送到控制器,否则不会发送。当前,当按下更新按钮时,我显示确认警报Javascript 如何在单击按钮时调用JS函数,然后在调用时打开弹出窗口?,javascript,asp.net,model-view-controller,bootstrap-4,Javascript,Asp.net,Model View Controller,Bootstrap 4,我正在使用JS函数向控制器发送值我想在向控制器提交值之前显示一个弹出窗口,如果按下弹出窗口确认按钮,则保存值,然后将值发送到控制器,否则不会发送。当前,当按下更新按钮时,我显示确认警报 //Bootstrap and JS Code @using (Html.BeginForm("BulkUpdate", "Home", FormMethod.Post)) { @Html.AntiForgeryToken() <div class="container col-md-12">
//Bootstrap and JS Code
@using (Html.BeginForm("BulkUpdate", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="container col-md-12">
<table id="myTable" class="cell-border compact hover">
<thead>
<tr>
<th>@Html.DisplayNameFor(m => m.First().Id)</th>
<th>@Html.DisplayNameFor(m => m.First().TagName)</th>
<th>@Html.DisplayNameFor(m => m.First().TagCategory)</th>
<th>@Html.DisplayNameFor(m => m.First().TagValue)</th>
<th> Action</th>
</tr>
</thead>
<tbody>
@for(int i =0; i < Model.Count();i++)
{
<tr>
<td>
@Html.DisplayFor(m => Model[i].Id)
@Html.HiddenFor(m => Model[i].Id)
</td>
<td>
@Html.DisplayFor(m => Model[i].TagName)
</td>
<td>
@Html.DisplayFor(m => Model[i].TagCategory)
</td>
<td>
@Html.EditorFor(m => Model[i].TagValue, new { htmlAttributes = new { @id = "TagVaule_" + Model[i].Id, @class = "form-control" } })
</td>
<td>
<button type="button" class="btn btn-secondary" onclick="UpdateRow(@Model[i].Id)">Update</button>
</td>
</tr>
}
</tbody>
</table>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="BulkUpdate" class="btn btn-default" />
</div>
</div>
</div>
///Dilog Box
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Confirm Update</button>
</div>
</div>
</div>
</div>
}
@section Scripts{
<script>
$(document).ready(function () {
$('#myTable').DataTable();
});
</script>
<script>
//Confirmation Function
function confirmupdate(id) {
}
//Update Row Function
function UpdateRow(id)
{
var tagvalue = $("#TagVaule_" + id).val();
var done = confirm('Do you want to update the Tag Value To '+tagvalue)
if (done) {
$.ajax(
{
type: "POST",
url: '@Url.Action("Update","Home")',
data: {
id: id,
value: tagvalue
},
});
}
else {
}
}
</script>
}
//引导和JS代码
@使用(Html.BeginForm(“BulkUpdate”、“Home”、FormMethod.Post))
{
@Html.AntiForgeryToken()
@DisplayNameFor(m=>m.First().Id)
@Html.DisplayNameFor(m=>m.First().TagName)
@DisplayNameFor(m=>m.First().TagCategory)
@DisplayNameFor(m=>m.First().TagValue)
行动
@对于(int i=0;iModel[i].Id)
@Html.HiddenFor(m=>Model[i].Id)
@Html.DisplayFor(m=>Model[i].标记名)
@DisplayFor(m=>Model[i].TagCategory)
@EditorFor(m=>Model[i].TagValue,new{htmlAttributes=new{@id=“TagVaule”+Model[i].id,@class=“form control”})
更新
}
///Dilog盒
情态标题
&时代;
...
接近
确认更新
}
@节脚本{
$(文档).ready(函数(){
$('#myTable').DataTable();
});
//确认功能
函数确认更新(id){
}
//更新行函数
函数UpdateRow(id)
{
var tagvalue=$(“#TagVaule"+id).val();
var done=confirm('是否要将标记值更新为'+tagvalue〕)
如果(完成){
$.ajax(
{
类型:“POST”,
url:'@url.Action(“更新”、“主页”),
数据:{
id:id,
值:tagvalue
},
});
}
否则{
}
}
}
或者有几十个现成的基于JavaScript的弹出式对话框小部件可在线使用。几十个。你可以在几秒钟内找到一个,而不是等待我们告诉你。ADyson我不是在寻找弹出式模型基本上我想知道如何使用JS函数中的模型ID调用模型。我是JS中的一个noob。“我不是在寻找弹出式模型。”。。好的,但在问题中你说“我想显示一个弹出窗口”。那我们该怎么想呢?如果显示弹出窗口不是问题,那么请在问题中更清楚地解释您的问题(不仅仅是快速评论)。阅读评论后,这没有意义。你想要实现什么?JS行为不端吗?是否等待您的确认?我很困惑。