当用程序更新字段时,如何在更新时运行jquery函数

How to run jquery function on update when field is updated programatically?

本文关键字:更新 函数 运行 jquery 程序 字段      更新时间:2023-09-26

我制作了一个函数loadcomputers(),该函数用id=computer对选择列表进行二次更新loadcomputers()从具有id="rating"的输入字段获得滤波器具有id="rating"的输入字段由另一个函数rate(item)自动填写问题是,当id="rating"的输入字段被自动填写时,函数loadcomputers((不会加载,但如果我手动键入,它可以工作

 <div>
    <ul>
      <li>
        <input class="ccheckbx" type="checkbox" name="application[]" value="1" onClick="rate(this);"  />Office              
      </li>
      <li>
        <input class="ccheckbx" type="checkbox" name="application[]" value="2" onClick="rate(this);"  />Game 
      </li>     
    </ul>
      <input type="text" id="rating" oncchange="loadcomputers()"/>
      <select name="computer" id="computer"></select>
</div>
--------------------------------------------------
  var total = 0;
function rate(item){
    if(item.checked){
       total+= parseInt(item.value);
    }else{
       total-= parseInt(item.value);
    }
    //alert(total);
    document.getElementById('rating').value = total + "";
}
-------------------------------------------
function loadcomputers() {
    $val = $('#rating').val();
    $.post('http://exemple1.com/action/subs/pcdrop2.php', {
    rating: $val
    }, function (data) {
    $('#computer').html(data);
});
}

您可以使用自己触发事件

$('#rating').trigger('change');

loadComputers()

btw:有一个打字错误,应该是onchange,你有oncchange

相关文章: