表单函数未执行

Form function is not executed

本文关键字:执行 函数 表单      更新时间:2024-07-03

我正在尝试在表单中执行更改函数。

<ul class="list booking-filters-list">
  <li>
     <h5 class="booking-filters-title">Price</h5>
      <input type="text" id="price-slider">
  </li>
  <li>                                    
    <h5 class="booking-filters-title">Star Rating</h5>
    <form id="hotelRating" name="hotelRating" onchange="filterBy()">
    <div class="checkbox">
        <label>
            <input class="i-check" type="checkbox" name="5" value="5.0" />5 star</label>
    </div>
    <div class="checkbox">
        <label>
            <input class="i-check" type="checkbox" name="4" value="4.0" />4 star</label>
    </div>
    <div class="checkbox">
        <label>
            <input class="i-check" type="checkbox" name="3" value="3.0" />3 star</label>
    </div>
    <div class="checkbox">
        <label>
            <input class="i-check" type="checkbox" name="2" value="2.0" />2 star</label>
    </div>
    <div class="checkbox">
        <label>
            <input class="i-check" type="checkbox" name="1" value="1.0" />1 star</label>
    </div>
    </form>
  </li>
</ul>

脚本功能:

<script>
  function filterBy() { 
  $('.searchtable').addClass('hide');
  $('.spinner').removeClass('hide');
  $.ajax({
        type: 'GET',
        data: {'name':'<?php echo strval($_GET['name']); ?>','arrival':'<?php echo strval($_GET['arrival']); ?>','departure':'<?php echo strval($_GET['departure']);?>','guests':'<?php echo strval($_GET['guests']);?>','propertyCategory':$("#hotelType input[type='checkbox']:checked").val(),'minStarRating':$("#hotelRating input[type='checkbox']:checked").val(),'order_by':$('#order_by').val()},
        url: '<?php echo $baseUrl ?>/hotels/hotelFilterResult.php',

        success: function (data) {
            alert('data loaded succesfully');
            alert(this.url);
            $('.searchtable').replaceWith(data);
            $('.spinner').addClass('hide');
            $('.searchtable').removeClass('hide');
        },
        error: function (xhr) {
            alert('data not loaded');
        }
 });
 }
</script>

我已经将函数filterBy()设置为在表单中执行onchange,但当我设置其中一个复选框时,什么都没有发生。

EDIT:如果我删除类"I-check",就会调用该函数。为什么会这样?

有人能认出我做错了什么吗?

           console.log("recieved data-------*'n'nResponse : " + response +"'n'nStatus : " + status);

$('.searchtable').replaceWith(data);

添加此控制台语句并打开浏览器和手表控制台的开发工具。我怀疑它是否会被触发,因为更改不会在您将其添加到表单时注册。您可以将类添加到复选框中,如class="mycheckbox"

然后在jquery 中

$('.mycheckbox').click ...

添加之前准备好的文档。