javascript - 如何在 ASP.NET Core 2.1 中使用自动完成输入引发模式
问题描述
我需要在 ASP-NET Core 2.1 的模式中实现 JQuery 自动完成
问题是它没有显示任何内容,为什么我会出现这种行为?
我附上我的代码:
<html>
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
@*<link rel="stylesheet" href="/resources/demos/style.css">*@
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
jQuery(document).ready(function ($) {
$("#txtSearch").autocomplete({
source: '@Url.Action("BuscarProducto")'
});
});
</script>
</head>
<body>
<div style="margin-top:60px; margin-bottom:20px" align="right">
<a href="#" class="btn btn-primary" data-toggle="modal" data-target="#agregarProducto"><i class="glyphicon glyphicon-plus"></i> Agregar Material </a>
</body>
</html>
<!--MODAL AGREGAR PRODUCTO-->
<div class="modal fade" id="agregarProducto">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Agregar Material</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="alert alert-dismissible alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Tener en cuenta!</strong> <a> para agregar más de una unidad habilite</a><strong> agregar cantidad.</strong>
</div>
<form id="myForm">
<label>Producto</label>
<input type="text" class="form-control" name="searchTerm" id="txtSearch" />
<br />
<br />
<label>Agregar Cantidad</label>
<input type="text" class="form-control" name="cantidad" id="idcantidad" />
</form>
</div>
<div class="modal-footer">
<input type="button" value="Agregar Material" class="btn btn-primary" id="btnSubmit" />
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
如您所见...我的 Json 方法返回从模态输入的建议
但由于某种原因,它没有显示模式中指示的输入中的建议,这是怎么回事?我忘了做什么?对我有什么帮助吗?
解决方案
您可以使用 apendTo 选项,如下所示:
更改您的 HTML:
<form id="myForm">
<label>Producto</label>
<input type="text" class="form-control" name="searchTerm" id="txtSearch" />
@*add this div*@
<div id="Searchdata"></div>
<br />
<br />
<label>Agregar Cantidad</label>
<input type="text" class="form-control" name="cantidad" id="idcantidad" />
</form>
改变你的 jQuery:
jQuery(document).ready(function ($) {
$("#txtSearch").autocomplete({
source: '@Url.Action("BuscarProducto")'
});
$("#txtSearch").autocomplete("option", "appendTo", "#Searchdata");
});
推荐阅读
- mysql - 多对多表 id 的最佳实践
- html - 不知道如何让我的按钮链接到另一个 html 页面:(
- sql - 如何使用在事务中创建的新表
- c# - 选择根据列表检查的已选中列表框项目
- python - 自定义应用程序指示器在 Ubuntu 中工作,但是当我从登录启动菜单将 Ubuntu 更改为 Gnome 时无法工作
- powershell - PowerShell shell 脚本运行窗口自动关闭:Start-Process vs ./
- c++ - 如何在 C++ 中使用 SDL2 和 OpenGL 在移动圆上渲染纹理?
- performance - Kotlin 中 forEach 的慢速范围
- reactjs - 在 getInitialProps 中找不到 isServer
- python - 测试几乎是回文