javascript - $('#details').change() 不执行函数
问题描述
我有以下代码:
$('#details').on('change', (e) => {
console.log('change detected');
$('#details').find('*').attr('disabled', true);
$.ajax({
//...
});
function ResetFilters() {
$('#Neighbourhoods')[0].selectedIndex = 0;
$('#LowestPrice')[0].value = 0;
$('#HighestPrice')[0].value = 999;
$('#LowestReviews')[0].value = 0;
$('#HighestReviews')[0].value = 10;
$('#details').change();
}
不幸的是$('#details').change(); 不执行上面定义的 onchange 方法。
我也试过$('#details').trigger('change'); 但这也没有用。
有谁知道我做错了什么?
欢迎任何建议。
编辑:
这是我的 html(我使用 asp.net)
@model AirBnB.ViewModels.ListingsViewModel
@await Html.PartialAsync("City", Model.Details)
<hr/>
<h4>Filters</h4>
<form action="/" method="post" id="details" class="details-block">
@await Html.PartialAsync("Neighbourhoods", Model.Details)
@await Html.PartialAsync("Prices", Model.Details)
@await Html.PartialAsync("Reviews", Model.Details)
@await Html.PartialAsync("ResetFilters")
</form>
<script src="~/js/filter.js" asp-append-version="true"></script>
<hr/>
@await Html.PartialAsync("Charts")
解决方案
细节是一种形式,也许你的意思是
$('#details').on('submit', (e) => {
console.log('change detected');
$('#details').find('*').attr('disabled', true);
$.ajax({
//...
});
推荐阅读
- python - 使用 pip 下载的 pyinstaller 安装后无法正常工作
- swagger - Swagger 未加载 - 无法加载 API 定义:错误未定义消息
- java - 如何启动多个线程
- tensorflow - python中的线性回归(张量流)
- gtk - 时间变化时更新 Gtk.Label dynamicall
- amazon-sqs - CloudWatch 事件指标 - DeadLetterInvocations
- python - 在 Docker 中使用 Xlib.display 包时出错
- javascript - 这两种语法有什么区别
- scripting - grep 输出的最后几行
- qt - 如何在不使用 QCustomPlot 的情况下在 Qt 中创建实时散点图?