Javascript 当字段以编程方式更新时,如何在更新时运行jquery函数?

Javascript 当字段以编程方式更新时,如何在更新时运行jquery函数?,javascript,jquery,html,Javascript,Jquery,Html,我制作了一个函数loadcomputers(),该函数用id=computer loadcomputers()使用id=“rating” 带有id=“rating”的输入字段由另一个函数自动填写rate(项目) 问题是当id=“rating”的输入字段自动填写时,函数loadcomputers()不会加载,但如果我手动键入,它会工作 <div> <ul> <li> <input class="ccheckbx" ty

我制作了一个函数
loadcomputers()
,该函数用
id=computer
loadcomputers()
使用
id=“rating”
带有
id=“rating”
的输入字段由另一个函数自动填写
rate(项目)
问题是当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);
});
}

  • 办公室
  • 游戏
-------------------------------------------------- var合计=0; 功能费率(项目){ 如果(选中项){ 总计+=parseInt(项值); }否则{ 总计-=parseInt(项目值); } //警报(总数); document.getElementById('rating')。value=total+“”; } ------------------------------------------- 函数loadcomputers(){ $val=$(“#评级”).val(); $.post($)http://exemple1.com/action/subs/pcdrop2.php', { 评级:$val },函数(数据){ $('#computer').html(数据); }); }
您可以使用

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


顺便说一句:这里有一个输入错误,应该是
onchange
,你有
onchange

可能重复的谢谢,但不完全相同。谢谢,我试过了,但不起作用<代码>函数loadcomputers(){$val=$('#评级').val();$.post('http://onlinepcdoc.com/action/subs/pcdrop2.php“,{rating:$val},函数(数据){$('#computer').html(数据);$('#rating').trigger('change');})}
I添加了
$('#rating').trigger('change')在费率(项目)上安装,并正常工作。非常感谢。