Javascript 为什么jQuery函数不';“不要跑去展示”;“模态”;
我想把一个按钮在网页上,并显示一个模式,当你点击它。 我用jQuery编写了OnClick事件函数Javascript 为什么jQuery函数不';“不要跑去展示”;“模态”;,javascript,jquery,asp.net,asp.net-mvc,Javascript,Jquery,Asp.net,Asp.net Mvc,我想把一个按钮在网页上,并显示一个模式,当你点击它。 我用jQuery编写了OnClick事件函数 <div class="modal fade" id="Modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class=&
<div class="modal fade" id="Modal" 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="ModalLabel">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" id="modalbody">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
情态标题
&时代;
接近
保存更改
@节脚本{
$(“BtnewGroup”)。在(“单击”上,函数(){
$.get(“/Admin/PageGroups/Create”,函数(结果){
$(“模态”).Modal();
$(“ModalLabel”).html(“创建新组”);
$(“modalbody”).html(结果);
})
});
}
在渲染部分之前有参考:
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
@RenderSection("scripts", required: false)
@RenderSection(“脚本”,必需:false)
问题在于jquery选择器。您缺少ID选择器。
请在下面查看
$("#btnNewGroup").on("click",function () {
$.get("/Admin/PageGroups/Create", function (result) {
$("#Modal").modal();
$("#ModalLabel").html("Create new group");
$("#modalbody").html(result);
})
});
确保jquery在引导之前。在您的控制台(浏览器F12)中进行检查,它们可能会显示错误消息。关于您的代码,请检查-您在所有选择器中缺少
id
选择器$(“模式”)
->$(“#模式”)
etcBesides缺少选择器前缀,你也应该用文档的ready
方法包装你的代码。伙计们,谢谢你们的回答,我照你说的做了,问题解决了
$("#btnNewGroup").on("click",function () {
$.get("/Admin/PageGroups/Create", function (result) {
$("#Modal").modal();
$("#ModalLabel").html("Create new group");
$("#modalbody").html(result);
})
});