首页 > 解决方案 > $('#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")

标签: javascriptjqueryhtmlasp.net

解决方案


细节是一种形式,也许你的意思是

$('#details').on('submit', (e) => {
console.log('change detected');
$('#details').find('*').attr('disabled', true);
$.ajax({
   //...
});

推荐阅读